fluttercandies / flutter_image_compress

flutter image compress
MIT License
636 stars 214 forks source link

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

Open mariopepe opened 2 years ago

mariopepe commented 2 years ago

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

nammaapp commented 2 years ago

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.

leahciMic commented 1 year ago

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.