Resize and image!

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
bekalariak
Posts: 6
Joined: 2018-05-02T06:18:59-07:00
Authentication code: 1152

Resize and image!

Post by bekalariak » 2018-06-04T06:11:18-07:00

Hi everyone!!

I am trying to resize (in a perl script) an image that has these dimensions 4272x2848 to other one that has 1280x720. Of course, while the aspect ratios are different, the image has to be 1) cuted above/right and below/left or 2) expanded.
Well, I cant find the solution to get the first option. Using the code below I reach an image expanded but I do not want that.

------>$iamge->Resize(geometry=>'1280x720!');
or
------>$iamge->Resize(width=>$width, height=>$height);

I try every thing, Scale, Extent, Resize, Gravity... But I do not get it. :shock: :shock:

snibgo
Posts: 10927
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize and image!

Post by snibgo » 2018-06-04T06:31:14-07:00

I don't understand the question. The aspect ratios are different. 4272:2848 = 1.5:1, and 1280:720 is 1.778:1.

If you want to stretch the image to be exactly 1280x720, use "!". If you want to resize but keep the same aspect ratio and fit within 1280x720, don't use "!". The result will be 1080x720.
snibgo's IM pages: im.snibgo.com

bekalariak
Posts: 6
Joined: 2018-05-02T06:18:59-07:00
Authentication code: 1152

Re: Resize and image!

Post by bekalariak » 2018-06-04T07:02:31-07:00

Sorry for my explanation. Yes, I want to stretch the image to be exactly 1280x720. But when I do that, the image looks extended. So to avoid that i want to "cut" the image above/below or left/right.

snibgo
Posts: 10927
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize and image!

Post by snibgo » 2018-06-04T07:19:39-07:00

If you use "^", the output is 1280x853. You can then crop to 1280x720. Does that do what you want?
snibgo's IM pages: im.snibgo.com

bekalariak
Posts: 6
Joined: 2018-05-02T06:18:59-07:00
Authentication code: 1152

Re: Resize and image!

Post by bekalariak » 2018-06-06T03:42:39-07:00

Yes, that was exactly that I wanted! The simplest idea are the easiest.
Only a note, for future people, when we Crop the image the part of the botton is the croped. So, I use "gravity=>'Center'" to crop equaly.

------>$image->Resize(geometry=>'1280x720^');
------>$image->Crop(geometry=>'1280x720', gravity=>'Center');

Thanks

Post Reply