hm21 / pro_image_editor

The pro_image_editor is a Flutter widget designed for image editing within your application. It provides a flexible and convenient way to integrate image editing capabilities into your Flutter project.
https://hm21.github.io/pro_image_editor/
BSD 3-Clause "New" or "Revised" License
94 stars 59 forks source link

how we can enforce user to crop the image? #146

Closed Abhishek01039 closed 2 months ago

Abhishek01039 commented 2 months ago

Platforms

Android, iOS

Description

how do we force users to crop the image in the aspectRatios which we have given to them?

cropRotateEditorConfigs: CropRotateEditorConfigs(
              initAspectRatio: dimension == ImageDimension.square ? 1 : 4 / 3,
              canChangeAspectRatio: false,
              aspectRatios: [
                dimension == ImageDimension.square ? squareRatio : postRatio,
              ],
            ),

Why

No response

Abhishek01039 commented 2 months ago

hello @hm21 can you please take a look at this?

Thanks!

hm21 commented 2 months ago

Do I understand you correctly that you want to open the normal editor with all the subeditors (like paint or filter editor), but you want to initialize the editor with the specific size?

If so, you have now two options:

Option 1 Easy

You open first the crop-rotate-editor as a standalone editor example and after your user crop the size he wants, you open the main-editor with all other editors, like the filter editor.

Option 2 Hard

You can set the transform configs manually when you open the editor. The complicated case here is that you need to calculate your image size, and it's scale factor, to fit it to the screen. Below is a small example.

callbacks: ProImageEditorCallbacks(
  mainEditorCallbacks: MainEditorCallbacks(
    onAfterViewInit: () {
      editorKey.currentState!.stateHistory.first.transformConfigs =
          TransformConfigs(
        /// Set the required scalefactor that it fit to the screen
        scaleUser: 1.2,

        /// Set the aspect ratio
        aspectRatio: 1,

        /// Set your crop size
        cropRect: Rect.fromLTWH(
          0,
          0,

          /// The crop size
          MediaQuery.of(context).size.width,
          MediaQuery.of(context).size.width,
        ),

        /// Ignore stuff below
        angle: 0,
        originalSize: Size.infinite,
        scaleRotation: 1,
        cropEditorScreenRatio: 0,
        flipX: false,
        flipY: false,
        offset: const Offset(0, 0),
      );
    },
  ),
),

Btw, I will move your question to the Discuss tab in the Q&A category because that tab is better for questions.