Page 1 of 1

Resizing with crop

Posted: 2008-10-04T07:47:15-07:00
by porton
I have an image and a given size. Image must be changed to fit exactly into given size. It must be cropped (with -gravity Center) if either width or height does not fit into the given size. Resizing must be proportional. How?

Re: Resizing with crop

Posted: 2008-10-04T12:29:12-07:00
by magick
Use Resize() to resize the image. By default it maintains the aspect ratio. Use Extent() with a gravity of center to fill in any empty space. Something like Resize('400x400') and Extent(geometry=>'400x400', background=>'white', gravity=>'center').

Re: Resizing with crop

Posted: 2008-10-04T13:31:10-07:00
by porton
magick wrote:Use Resize() to resize the image. By default it maintains the aspect ratio. Use Extent() with a gravity of center to fill in any empty space. Something like Resize('400x400') and Extent(geometry=>'400x400', background=>'white', gravity=>'center').
I don't understand how Resize() maintains the aspect ratio. AFAIK, Resize(geometry => "400x400") does not maintain aspect ratio. Is Resize('400x400') different than Resize(geometry => "400x400")?

Also I need (before cropping) to resize the image to the size probably more than the (final) size of crop, and only then to accomplish crop. Will your code do this?

Re: Resizing with crop

Posted: 2008-10-05T07:14:16-07:00
by porton
magick wrote:Use Resize() to resize the image. By default it maintains the aspect ratio. Use Extent() with a gravity of center to fill in any empty space. Something like Resize('400x400') and Extent(geometry=>'400x400', background=>'white', gravity=>'center').
Oh, well, now I noticed that Resize() maintains the aspect ratio. But using Extent() for my task is wrong. Extent() fills borders with a background color. I instead need to resize the image so that it becomes of the minimal size such that it completely covers the given size (minimum size which is greater than the given size, maintaining aspect ratio), and crop the center (-gravity Center).

How?

Re: Resizing with crop

Posted: 2008-10-05T07:31:34-07:00
by magick
Perl is a scripting language. You can compute the dimension you need with Get('width') and Get('height') and then Resize(width=>???, height=>???).