TOAST UI ImageEditor

repository·master·Indexed 27 days ago

https://github.com/nhn/tui.image-editor

A full-featured image editing library built on HTML5 Canvas offering photo manipulation, powerful filters, and customizable themes. It is available as a core JavaScript library (tui-image-editor) and as wrapper components for React (@toast-ui/react-image-editor) and Vue (@toast-ui/vue-image-editor). Key features include cropping, flipping, rotation, drawing, text overlays, and a wide array of visual filters such as Grayscale, Blur, and Brightness.

Tokens
14.9K
Snippets
42
Records
76
Agent score
93%

What's inside tui-image-editor

  1. Overview of TOAST UI ImageEditor packages

    master

    TOAST UI ImageEditor is a full-featured image editor built using HTML5 Canvas. It provides powerful filters and photo manipulation capabilities. The project is available in three main packages depending on your technology stack:

    • tui-image-editor: The core plain JavaScript component.
    • @toast-ui/vue-image-editor: A Vue wrapper component.
    • @toast-ui/react-image-editor: A React wrapper component.
  2. Understand the ImageEditor Architecture

    master

    The image editor is structured into two major layers:

    1. Middle Layer: Managed by the ImageEditor object, it handles the API and communicates with the UI. It consists of the Invoker (manages Undo/Redo), Command, and CommandFactory (registers and creates commands).
    2. Graphics Layer: The drawing core. It uses Canvas (powered by fabric.js) to perform drawing operations. This layer includes Component modules for specific functions (like cropping or text) and manages Drawing Modes.

    You can use the built-in UI via the includeUI option, or implement your own UI by interacting directly with the ImageEditor API.

  3. Customize Themes

    master

    TUI Image Editor comes with default themes and provides an API for full customization:

    • Built-in Themes: Includes black and white themes.
    • Customization: You can modify the existing theme files or use the provided API to create entirely new custom themes to match your application's design.
  4. Explore Integration Functions

    master

    The editor includes several built-in integration functions for managing the editing workflow:

    • Download: Save the edited image.
    • Image Load: Load a new image into the canvas.
    • Undo/Redo: Revert or re-apply previous actions (supports keyboard shortcuts).
    • Reset: Revert the image to its original state.
    • Delete Object: Remove specific elements like Shapes, Lines, or Mask Images from the canvas.
  5. Explore Photo Manipulation and Filter Features

    master

    The TUI Image Editor provides a comprehensive suite of photo manipulation and filtering tools:

    Photo Manipulation

    • Crop: Adjust the visible area of the image.
    • Flip: Mirror the image horizontally or vertically.
    • Rotation: Rotate the image.
    • Drawing: Freehand drawing on the image.
    • Shape: Add geometric shapes.
    • Icon: Add icons to the image.
    • Text: Add text overlays.
    • Mask: Apply mask filters.
    • Image Filter: Apply various visual filters.

    Powerful Filter Functions

    Available filters include:

    • Grayscale, Invert, Sepia, Sepia2
    • Blur, Sharpen, Emboss
    • RemoveWhite, Brightness, Noise, Pixelate
    • ColorFilter, Tint, Multiply, Blend, Blend-righten, Blend-diff
  6. Load the ImageEditor component

    master

    You can load the ImageEditor component using ES modules, CommonJS, or via <script> tags. If you only need the Vue wrapper component without the full library, you can import the Single File Component directly.

    // es modules
    import { ImageEditor } from '@toast-ui/vue-image-editor';
    
    // commonjs require
    const { ImageEditor } = require('@toast-ui/vue-image-editor');
    
    // Using only Vue wrapper component (Single File Component)
    import ImageEditor from '@toast-ui/vue-image-editor/src/ImageEditor.vue';
  7. Install @toast-ui/vue-image-editor via npm

    master

    Install the Vue wrapper for TOAST UI Image Editor using npm.

    Note: If you install other packages and lose the dependency on fabric, you must manually reinstall fabric@~4.2.0 using the --no-save --no-optional flags.

    npm install --save @toast-ui/vue-image-editor
    
    # If fabric dependency is lost, run:
    npm install --no-save --no-optional fabric@~4.2.0
  8. Save edited images to a server

    master

    The image editor does not automatically save files to a server. To save an edited image, you must extract the image data as a Base64 string using toDataURL() and then transmit that data to your server via an Ajax request (e.g., POST).

    // Step 1. Import image data to be saved in the image editor.
    var dataURL = imageEditor.toDataURL();
    
    // Step 2. Send base64 encoded image data via Ajax to the server.
    $.ajax({
      type: 'POST',
      url: serverUrl,
      data: {
        imgBase64: dataURL, // Data from Step 1.
      },
    }).done(function () {
      console.log('saved!');
    });