-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to reproduce CroppableImageData
transformations on the server?
#54
Comments
Hi! You can see the cropping implementation via Flutter's Canvas in https://github.com/kekland/croppy/blob/06e84b3597571fa1f8f6818f604d80f376bf44fc/lib/src/image/crop_image.dart#L31C1-L32C1. In short (
As for the transformation matrix itself:
Here,
croppy/lib/src/model/croppable_image_data.dart Lines 80 to 95 in 06e84b3
So, the |
Thank you for the detailed explanation! It seems a bit complex but very informative. I tried implementing a method to generate the ImageMagick command based on the transformations, but the result is still not perfect. Here’s my current implementation: class CroppableImageData extends Equatable {
// ...
String generateImageMagickCommand(String inputFile, String outputFile) {
final cropLeft = cropRect.left.round();
final cropTop = cropRect.top.round();
final cropWidth = cropRect.width.round();
final cropHeight = cropRect.height.round();
final scaleX = totalImageTransform.getRow(0)[0];
final scaleY = totalImageTransform.getRow(1)[1];
final shearX = totalImageTransform.getRow(0)[1]; // Horizontal shear
final shearY = totalImageTransform.getRow(1)[0]; // Vertical shear
final rotationZDegrees = math.atan2(shearY, scaleY) * 180 / math.pi;
// ImageMagick cropping
final cropCommand = "-crop ${cropWidth}x$cropHeight+$cropLeft+$cropTop";
// ImageMagick scaling
final resizeCommand = "-resize ${scaleX * 100}x${scaleY * 100}";
// ImageMagick rotation
final rotateCommand = "-rotate ${rotationZDegrees.toStringAsFixed(2)}";
// ImageMagick shear
final shearCommand =
"-shear ${shearX.toStringAsFixed(2)}x${shearY.toStringAsFixed(2)}";
final command =
"magick convert $inputFile $cropCommand $resizeCommand $shearCommand $rotateCommand $outputFile";
return command;
}
// ...
} |
Hm, from what I can see the difference could be that in croppy the crop mask isn't translated (it's at the origin), and the image itself is moved by It'd also help if you could share the image (as shown in Croppy), and what the ImageMagick result is |
I plan to handle image cropping on the server side by exporting the
CroppableImageData
to the server. Could you clarify the order in which transformations are applied to produce the final image?For example, is it:
or
This information would be helpful for replicating the transformation pipeline accurately.
The text was updated successfully, but these errors were encountered: