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.

Resize image to exact 64x64 Pixels

Postby Achim74 » 2009-05-15T03:14:58+00:00

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.
Achim74
 

Re: Resize image to exact 64x64 Pixels

Postby fmw42 » 2009-05-15T08:56:22+00:00

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

Add +repage after your crop
User avatar
fmw42
 
Posts: 14897
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Resize image to exact 64x64 Pixels

Postby Achim74 » 2009-05-15T12:34:14+00:00

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

Greetings
Achim74
 

Re: Resize image to exact 64x64 Pixels

Postby fmw42 » 2009-05-15T15:27:12+00:00

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
User avatar
fmw42
 
Posts: 14897
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA


Return to Developers

Who is online

Users browsing this forum: Google Adsense [Bot] and 5 guests