flutter_image_compress icon indicating copy to clipboard operation
flutter_image_compress copied to clipboard

[documentation] how to resize image and what is "srcWidth" and "srcHeight"

Open mariopepe opened this issue 2 years ago • 2 comments

  1. let's say I have an image 1000 x 1000, how can I BOTH compress the quality AND resize it to say 500 x 500 ?

  2. I have seen in the docs srcWidth and srcHeight, what is this?

Thanks

mariopepe avatar Mar 17 '22 22:03 mariopepe

I'm no expert with this package but I don't think this is possible with current code. This only scales up the image if its lesser than minHeight/minWidth but not scales down if passed image bytes are of higher resolution.

var scaleW = srcWidth / minWidth; var scaleH = srcHeight / minHeight; var scale = math.max(1.0, math.min(scaleW, scaleH));

math.max always returns 1 or >1, so scaling down is not available. May be, using math.min(1.0, math.min(scaleW, scaleH)) could help in our case.

nammaapp avatar Aug 07 '22 03:08 nammaapp

The resize logic is extremely odd and confusing.

I've created a sheet that you can use to visualize what will happen with different parameters.

It can scale down, but has edge cases.

I would prefer to see a maxWidth and maxHeight and that it would keep it within those bounds but maintain the aspect ratio.

leahciMic avatar Oct 28 '22 02:10 leahciMic