Closed Ali1 closed 10 years ago
What exactly are you trying to do? It's not really possible to resize an image to a fixed size unless you are cropping it or fitting it.
There are some smart processes out there which first crop to get the desired ratio before resizing and then cropping again to make sure that last pixel or 2 are fixed up. This is how square avatars are generated most of the time.
On Monday, 20 January 2014, Miles Johnson notifications@github.com wrote:
What exactly are you trying to do? It's not really possible to resize an image to a fixed size unless you are cropping it or fitting it.
— Reply to this email directly or view it on GitHubhttps://github.com/milesj/uploader/issues/167#issuecomment-32729642 .
Sent from my iPhone
The crop and resize transformers respect aspect ratio. One of them should be able to do what you're looking for.
resize currently needs the mode argument
(default:width) - Use the width or height for aspect ratio calculations (accepts width or height)
and so it can't respect both equally
In my case, I want an image of for example 1000x400 to be resized and cropped to get a nice 210x210 avatar. I'm not sure which combination of transforms can achieve this.
The process would be:
If an image was smaller than 210x210 to start with, the first resize with mode "min" should have actually enlarged the image to get minimum dimensions of h=210 and w=210.
Crop resizes with aspect ratio before cropping, so yes it would be 525x210 before it crops. Have you tried?
Even running the tests work as they should. https://github.com/milesj/transit/blob/master/tests/Transit/Transformer/Image/CropTransformerTest.php#L16
ahhhh sugar! yep works perfectly! thanks mate
No problem.
Hi Miles. Your page says about the "Fit" transformer: "Allows one to fit an image within a certain dimension. Any gap in the background will be filled with a color. If no background fill is provided, the image will simply be resized." However the transformer does not allow an empty fill option throwing "Invalid RGB fill color". Other than a resize (which potentially makes the image looked squashed), I do not see a way of transforming an image into a fixed size avatar using the provided transformers?