Resize image to exact 64x64 Pixels

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Achim74

Resize image to exact 64x64 Pixels

Post by Achim74 »

Hello !

I hope I can explain in my poor english what I would like to do.

I want to resize a picture to exactly 64x64 Pixels without loosing aspect ratio by cropping either the width or height.

- The aspect ratio should be kept
- If the height or width is greater than 64 the picture should be cropped from the center
- Important too: If a image is smaller than 64px it should be also resized (make bigger) to 64x64

I used this code before:

Code: Select all

$command = "/usr/bin/convert $resized -resize 50% +profile \"*\" ".$dest_folder."images/avatar/temp.jpg";
passthru($command);
$command = "/usr/bin/convert ".$dest_folder."images/avatar/temp.jpg -gravity Center -crop 64x64+0+0  +profile \"*\" $output";
passthru($command);
But it resizes sometimes only one side to 64 .. so you get 64x45 or something ...

Can somebody help me please ... any help is appreciated .. Thank you very much !

PS: This don't work for me .. which version do I need ? I have 6.2.4

Code: Select all

widthxheight^  	Minimum values of width and height given, aspect ratio preserved.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize image to exact 64x64 Pixels

Post by fmw42 »

You need IM v6.3.8-3 to use -resize with ^

Add +repage after your crop
Achim74

Re: Resize image to exact 64x64 Pixels

Post by Achim74 »

Thank you for your reply. Unfortunately there is no possibility to install a newer version on this host. Is there a workaround ?

Greetings
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize image to exact 64x64 Pixels

Post by fmw42 »

You can script it by testing the image sizes. I wrote a bash script before the ^ option was available. See squareup at http://www.fmwconcepts.com/imagemagick/index.html
Post Reply