ProImageEditor Documentation

repository·stable·Indexed 18 days ago

https://github.com/hm21/pro_image_editor

A high-performance Flutter widget for professional-grade image editing. It features a comprehensive suite of tools including paint, text, crop, rotate, tune adjustments, filters, blur, and emoji/sticker editors. The library supports multi-threaded background processing via Isolates and Web Workers, non-destructive editing with undo/redo, and customizable UI themes such as Grounded, Frosted-Glass, and WhatsApp. It also provides extensive customization options for the main editor UI, loading dialogs, and layer interactions.

Tokens
12.3K
Snippets
36
Records
43
Agent score
62%

What's inside ProImageEditor

  1. Overview of ProImageEditor features

    stable

    ProImageEditor is a comprehensive Flutter widget for image manipulation. Key capabilities include:

    Editor Modules

    • Paint Editor: Freehand drawing, shapes (circles, arrows), and censoring (blur/pixelation).
    • Text Editor: Full text styling and customization.
    • Crop & Rotate: Flipping, rotating, and cropping.
    • Tune Adjustments: Brightness, contrast, saturation, etc.
    • Filter Editor: Predefined and custom filters.
    • Blur Editor: Localized blurring.
    • Emoji & Sticker Editors: Inserting emojis and custom image stickers.

    Core Capabilities

    • Multi-threading: Uses Isolates (native) or Web Workers (web) for background processing.
    • Non-destructive Editing: Undo/Redo support.
    • Layer Management: Reorder layers, interactive selection, and hit detection for paint layers.
    • Advanced UX: Zoom support, helper lines for alignment, multiselect, and enhanced desktop mouse/scaling support.
  2. Apply prebuilt editor designs

    stable

    The editor supports three distinct visual themes/designs that can be applied to the UI:

    • Grounded: A standard design approach.
    • Frosted-Glass: A design featuring frosted glass effects.
    • WhatsApp: A design mimicking the WhatsApp interface.
  3. Configure colored emojis for Web

    stable

    When deploying on the web, if you want emojis to be displayed in color by default (without relying on custom fonts like Noto Emoji), you must configure the Flutter engine initialization in your flutter_bootstrap.js file by setting useColorEmoji: true within the initializeEngine call.

    _flutter.loader.load({
        serviceWorkerSettings: {
            serviceWorkerVersion: {{flutter_service_worker_version}},
        },
        onEntrypointLoaded: function (engineInitializer) {
          engineInitializer.initializeEngine({
            useColorEmoji: true, // add this parameter
            renderer: 'canvaskit'
          }).then(function (appRunner) {
            appRunner.runApp();
          });
        }
    });
  4. Implement Video Editing

    stable

    The editor supports full video generation on Android, iOS, and macOS. Support for Windows and Linux is planned.

    To keep the core image editor lightweight, video editing functionality is decoupled. You must manually add a video player package (like video_player) and use the companion package pro_video_editor to handle rendering workflows.

  5. Use ProImageEditor in Flutter

    stable

    To integrate the editor, use the ProImageEditor widget. The package provides several factory constructors for different input types, such as .network(). You can handle the completed edit via the callbacks parameter using ProImageEditorCallbacks.

    By default, the edited image bytes are returned in JPG format. If you use await inside onImageEditingComplete, the loading dialog will remain visible until your processing (e.g., uploading to a server) is finished.

    import 'package:pro_image_editor/pro_image_editor.dart';
    
    @override
    Widget build(BuildContext context) {
      return ProImageEditor.network(
        'https://picsum.photos/id/237/2000',
        callbacks: ProImageEditorCallbacks(
          onImageEditingComplete: (Uint8List bytes) async {
            /*
              Your code to process the edited image, such as uploading it to your server.
            */
            Navigator.pop(context);
          },
        ),
      );
    }
  6. Customize the iOS launch screen assets

    stable

    To change the image displayed during the app's launch on iOS, you can either replace the image files directly in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory or use Xcode for a more visual approach.

    Using Xcode:

    1. Open the iOS workspace by running open ios/Runner.xcworkspace from your terminal.
    2. In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the existing launch images.
    open ios/Runner.xcworkspace
  7. Identify the source type with EditorImageType

    stable

    You can determine how an image is being loaded by checking its type property, which returns an EditorImageType enum. This is useful for conditional logic in your UI or processing pipelines.

    Available EditorImageType values:

    • file: Loaded from a local file.
    • network: Loaded from a URL.
    • memory: Loaded from a byte array.
    • asset: Loaded from an asset path.
    EditorImageType imageType = myEditorImage.type;
    
    switch (imageType) {
      case EditorImageType.memory:
        // Handle memory image
        break;
      case EditorImageType.asset:
        // Handle asset image
        break;
      case EditorImageType.file:
        // Handle file image
        break;
      case EditorImageType.network:
        // Handle network image
        break;
    }
  8. Customize crop overlay opacity behavior

    stable

    The crop overlay is the area atop the image when the cropping area is smaller than the image. Its opacity is dynamic based on user interaction:

    1. Idle State: The opacity is set by cropOverlayOpacity.
    2. Active Interaction: When the user is actively interacting with crop bounds (e.g., dragging corners), the opacity is calculated as: cropOverlayOpacity - cropOverlayInteractionOpacity.

    Constraints:

    • cropOverlayOpacity must be between 0.0 and 1.0.
    • cropOverlayInteractionOpacity must be non-negative.
    • cropOverlayInteractionOpacity must not be greater than cropOverlayOpacity.
  9. Manage the Fake Hero animation in CropRotateEditor

    stable

    When enableFakeHero is set to true in CropRotateEditorInitConfigs, you must manually manage the visibility of the fake hero widget during navigation transitions to ensure a smooth UI.

    To hide the fake hero, listen to the AnimationStatus of your PageRouteBuilder and call hideFakeHero() on the editor's state when the animation status is AnimationStatus.completed.

    return Navigator.push<T?>(
      context,
      PageRouteBuilder(
        opaque: false,
        transitionDuration: duration,
        reverseTransitionDuration: duration,
        transitionsBuilder: (context, animation, secondaryAnimation, child) {
          void animationStatusListener(AnimationStatus status) {
            if (status == AnimationStatus.completed) {
              if (cropRotateEditor.currentState != null) {
                /// Remove the fake hero like that
                cropRotateEditor.currentState!.hideFakeHero();
              }
            } else if (status == AnimationStatus.dismissed) {
              animation.removeStatusListener(animationStatusListener);
            }
          }
          animation.addStatusListener(animationStatusListener);
          return page;
        },
        pageBuilder: (context, animation, secondaryAnimation) => page,
      ),
    );
  10. Configure Windows application metadata and versioning

    stable

    The Runner.rc file is a Microsoft Visual C++ resource script used to define the Windows-specific metadata for the application. Developers can modify this file to change the application's icon, version information, and descriptive properties (like Company Name and Product Name) that appear in Windows File Explorer.

    // Icon configuration
    IDI_APP_ICON            ICON                    "resources\\app_icon.ico"
    
    // Version and Metadata configuration
    VS_VERSION_INFO VERSIONINFO
     FILEVERSION VERSION_AS_NUMBER
     PRODUCTVERSION VERSION_AS_NUMBER
     // ...
     BEGIN
        BLOCK "StringFileInfo"
        BEGIN
            BLOCK "040904e4"
            BEGIN
                VALUE "CompanyName", "com.example" "\0"
                VALUE "FileDescription", "example" "\0"
                VALUE "FileVersion", VERSION_AS_STRING "\0"
                VALUE "InternalName", "example" "\0"
                VALUE "LegalCopyright", "Copyright (C) 2024 com.example. All rights reserved." "\0"
                VALUE "ProductName", "example" "\0"
                VALUE "ProductVersion", VERSION_AS_STRING "\0"
            END
        END
    END
  11. Configure image generation processor settings with ProcessorConfigs

    stable

    Use the ProcessorConfigs class to manage how background processors (isolates/threads) are utilized during image generation tasks. This allows you to control concurrency, the number of background workers, and initialization timing to balance performance and UI responsiveness.

    Configuration Options

    PropertyTypeDefaultDescription
    numberOfBackgroundProcessorsint2The number of background processors to use. Note: This is ignored if processorMode is set to auto, maximum, or minimum. Must be a positive integer.
    maxConcurrencyint1The maximum concurrency level. Note: This is ignored if processorMode is minimum. Must be a positive integer.
    processorModeProcessorModeProcessorMode.autoDetermines the strategy for processor utilization.
    initializationDelayDuration?nullAn optional delay before spawning background isolates. Use this to prevent UI jank during startup animations (e.g., Duration(milliseconds: 300)).

    Constraints

    • numberOfBackgroundProcessors must be > 0.
    • maxConcurrency must be > 0.
    const configs = ProcessorConfigs(
      numberOfBackgroundProcessors: 4,
      maxConcurrency: 2,
      processorMode: ProcessorMode.limit,
      initializationDelay: Duration(milliseconds: 300),
    );
  12. Configure the Crop and Rotate Editor with CropRotateEditorInitConfigs

    stable

    Use CropRotateEditorInitConfigs to initialize the Crop and Rotate Editor module. This class allows you to define transformation settings, themes, and lifecycle callbacks.

    Key configuration options include:

    • onDone: A callback triggered when the user completes the editing process. It provides the final TransformConfigs, a fitToScreenFactor, and optional ImageInfos.
    • enablePopWhenDone: A boolean (defaults to true) that determines if the editor widget should automatically pop from the navigation stack when editing is finished.
    • enableFakeHero: A boolean (defaults to false) used to enable a 'fake' hero widget for transition animations. If enabled, you are responsible for manually hiding the fake hero using cropRotateEditor.currentState!.hideFakeHero() once the transition completes.
    ```dart
    CropRotateEditorInitConfigs(
      configs: myConfigs,
      transformConfigs: myTransformConfigs,
      layers: myLayers,
      callbacks: myCallbacks,
      theme: myTheme,
      onDone: (transformations, fitToScreenFactor, imageInfos) {
        // Handle the done action
      },
    )```