Filerobot Image Editor Documentation

repository·master·Indexed 23 days ago

https://github.com/scaleflex/filerobot-image-editor

A lightweight, feature-rich image editing library for web applications supporting VanillaJS and React. It provides tools for cropping, resizing, annotating, watermarking, and applying filters. The library includes a React component wrapper via the react-filerobot-image-editor package and supports touch, mobile, and desktop environments.

Tokens
15.3K
Snippets
25
Records
63
Agent score
84%

What's inside Filerobot Image Editor

  1. Overview of Filerobot Image Editor (FIE)

    master
    Filerobot Image Editor (FIE) is a web-based image editing library that allows users to perform transformations such as resizing, cropping, flipping, fine-tuning, annotating, watermarking, and applying filters. It is designed to be easily integrated into web applications with minimal code and supports touch, mobile, and desktop environments.
  2. Enable Cloudimage Mode

    master

    By setting useCloudimage: true, the editor operates in cloudimage mode. Instead of returning the edited image itself, the editor will return a Cloudimage URL containing the transformations/operations.

    Note: In this mode, some tabs, tools, and options are not supported. You must provide a Cloudimage token to deliver images via their CDN.

  3. Install Filerobot Image Editor via NPM

    master

    You can install the editor using npm depending on your project type:

    For React projects

    Install the React component wrapper:

    npm install --save react-filerobot-image-editor

    For VanillaJS projects

    Install the core library:

    npm install --save filerobot-image-editor

    Note: If you are using an npm version older than 7, you may not need to install react-filerobot-image-editor separately if you are only using VanillaJS.

  4. Configure Fonts for Filerobot Image Editor

    master

    The library does not include font files by default. You must import the desired font family into your HTML or JS file before loading the plugin.

    By default, the editor uses Roboto (weights 400 and 500). If Roboto is not found, it falls back to Arial. If you provide a different fontFamily via the theme property, you must ensure that font is also imported.

  5. Prerequisites for React Component Installation

    master

    If you are installing the React component, the following peer dependencies are required. These are automatically included in the CDN bundle but must be manually installed for React projects:

    • react, react-dom: >= v17.0.0
    • react-konva: >= v17.0.1-1
    • styled-components: >= v5.3.5

    React Version Compatibility

    Ensure your react-konva version matches your React version according to this table:

    react & react-dom versionsreact-konva version
    v17.x.x>= v17.0.1-1 <= v17.0.2-6
    v18.x.xv18.x.x

    To install these dependencies:

    npm install --save react react-dom react-konva styled-components
  6. Install Filerobot Image Editor via CDN

    master

    For VanillaJS projects, you can include the editor directly via a <script> tag using the CDN. This method includes all necessary dependencies.

    <script src="https://scaleflex.cloudimg.io/v7/plugins/filerobot-image-editor/latest/filerobot-image-editor.min.js"></script>
    <script src="https://scaleflex.cloudimg.io/v7/plugins/filerobot-image-editor/latest/filerobot-image-editor.min.js"></script>
  7. Configure Crop Presets and Folders

    master

    You can define custom crop presets and organize them into folders using the presetsItems and presetsFolders configuration properties.

    CropPresetItem Configuration

    Each item in presetsItems or within a folder's groups must have a unique titleKey.

    • titleKey (string, Required): Translation key for the item title.
    • descriptionKey (string): Translation key for the description (e.g., showing the ratio or size).
    • ratio (string, Required if width/height are missing): The aspect ratio (e.g., 4/3, 'original', 'ellipse', 'custom').
    • width / height (number, Required if ratio is missing): Specific dimensions used to calculate the ratio.
    • icon (HTML Element | string | React Component): An icon displayed before the title.
    • disableManualResize (boolean): If true, disables resize inputs when this preset is selected (requires autoResize: true).
    • noEffect (boolean): If true, the crop is only a selection on the canvas and does not affect the image; you must handle the resulting crop manually.

    Presets Folders Structure

    Folders are organized via presetsFolders, which contain groups. Each group contains a titleKey and an array of items (which are CropPresetItem objects).

    {
      autoResize: true,
      presetsItems: [
        {
          titleKey: 'classicTv',
          descriptionKey: '4:3',
          ratio: 4 / 3,
          icon: CropClassicTv,
        },
        {
          titleKey: 'cinemascope',
          descriptionKey: '21:9',
          ratio: 21 / 9,
          icon: CropCinemaScope,
        },
      ],
      presetsFolders: [
        {
          titleKey: 'socialMedia',
          icon: Social,
          groups: [
            {
              titleKey: 'facebook',
              items: [
                {
                  titleKey: 'profile',
                  width: 180,
                  height: 180,
                  descriptionKey: 'fbProfilePhotoSize',
                },
                {
                  titleKey: 'coverPhoto',
                  width: 820,
                  height: 312,
                  descriptionKey: 'fbCoverPhotoSize',
                },
              ],
            },
          ],
        },
      ],
    }
  8. Set default tab and tool IDs

    master

    Use defaultTabId and defaultToolId to control the initial state of the editor when it opens.

    • defaultTabId: The ID of the tab that opens by default (Default: Adjust).
    • defaultToolId: The ID of the tool that opens by default within the specified tab. This must be a tool belonging to the defaultTabId.
  9. Configure Watermark settings

    master

    Customize how watermarks behave in the editor using the following configuration properties:

    • gallery: An array of strings or objects ({ url: string, previewUrl: string }) representing watermark image URLs. These appear in the watermark tab for users to select.
    • textScalingRatio: A number (default 0.33) that controls the scaling ratio for text watermarks.
    • hideTextWatermark: A boolean (default false) to disable the ability to add text watermarks.
    • onUploadWatermarkImgClick: A callback function triggered when the 'add image watermark' button is clicked. It receives a function loadAndSetWatermarkImgFn and returns a Promise<{ url: string, revokeObjectUrl?: boolean }> or void. This allows you to handle custom watermark uploads.

    Note on CloudImage mode: Text watermark width and multi-line support are not available in cloudimage mode. Text watermarks will always be a single line in the generated URL. Supported fonts for cloudimage mode must be provided via the Text property.

  10. Add custom saving options with moreSaveOptions

    master

    Use moreSaveOptions to add an overlay menu next to the save button. This allows you to provide additional saving workflows (e.g., 'Save as new version').

    Each object in the array must contain:

    • label (string, Required): The text shown to the user.
    • onClick (function, Required): A function receiving (triggerSaveModal, triggerSave).
      • triggerSaveModal opens the saving modal.
      • triggerSave saves directly.
      • Note: You must pass an onSave callback to either of these functions to handle the result.
    • icon (HTML Element | string | React Component): The icon displayed before the label.
    [
      {
        label: 'Save as new version',
        onClick: (triggerSaveModal, triggerSave) =>
          triggerSaveModal((...args) => {
            console.log('saved', args);
          }), // Required to pass the callback function
        icon: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">...</svg>', // HTML Element as string
      },
      {
        label: 'Save as new file',
        onClick: (triggerSaveModal, triggerSave) =>
          triggerSave((...args) => {
            console.log('saved', args);
          }), // Required to pass the callback function
        icon: () => (
          <svg
            width="14"
            height="14"
            viewBox="0 0 14 14"
            fill="none"
            xmlns="http://www.w3.org/2000/svg"
          >
            ...
          </svg>
        ), // React Function component
      },
    ];
  11. Configure Zoom behavior

    master

    Use the following properties to control zooming:

    • useZoomPresetsMenu (boolean): If true, clicking the zoom percentage shows preset percentages. Default is true.
    • disableZooming (boolean): If true, all zooming functionality and UI elements are removed. Default is false.