Pre defined size and ratio #198
-
Hey, Thanks for this amazing pub :) I have a new use case where a user uploads images to my app and I want the user to crop the image to 512x512 with face in the center. How can I fix pixel and ratio so that the user only needs to position their image via zoom and dragging? Is there the chance to position the initial position of the 512x512 window? Best |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hey Sebastian, If you want to allow users to zoom and drag with a fixed output size, you can configure this within the Please note that if the original image has a smaller size or if the user zooms in too much, the output size may be reduced due to insufficient pixels. As an example, an image with dimensions of Important: Update to version By the way, you might also find this example interesting, which demonstrates how to crop round profile pictures. CropRotateEditor.network(
'https://picsum.photos/id/230/2000',
key: _cropRotateEditorKey,
initConfigs: CropRotateEditorInitConfigs(
theme: ThemeData.dark(),
convertToUint8List: true,
configs: ProImageEditorConfigs(
designMode: platformDesignMode,
cropRotateEditorConfigs: const CropRotateEditorConfigs(
initAspectRatio: 1,
canChangeAspectRatio: false,
),
imageGenerationConfigs: const ImageGenerationConfigs(
maxOutputSize: Size(512, 512),
/// The default output format is `jpg` but you can change it like
/// below if you prefer as example `png`
/// outputFormat: OutputFormat.png,
/// If you wish to enforce a custom pixel ratio, you can
/// configure it below.
/// customPixelRatio: ,
),
),
onImageEditingComplete: (bytes) async {
/// TODO: Handle image bytes
print(bytes.length);
},
),
); |
Beta Was this translation helpful? Give feedback.
You're correct. After testing, I realized that when the image fits the screen width, I also get 384x384, but when it fits the screen height, I get 512x512. I'll open a new issue and attempt to fix it when I have time.
Meanwhile, I recommend removing the maximum output size from the
ImageGenerationConfigs
and cropping the image manually. This task is straightforward and requires only a few lines of code. You can use the image package, which is already included in your app, since the image editor depends on it. Below is an example code snippet demonstrating how to crop the image. Optionally, you can also use isolates or web workers combined with a Completer to prevent your UI from freezing./…