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 »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize and image!

Post by snibgo »

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 »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize and image!

Post by snibgo »

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 »

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