Hello:
I am a user of IM, currently on 6.3.5-q16 although I have tried solving my issue by using 6.7.4-q16 to no avail. I am using Windows Server2003, Apache and PHP 5.3.x.
A website I am writing needs to create square thumbnails of 140x140px from uploaded images.
The uploaded images may be portrait or landscape, and have varying aspect ratios.
I am trying to find a reliable way of creating a thumbnail from the uploaded image. Currently I use:
convert... -thumbnail 210x -gravity center -crop 140x140+0+0
this works reasonably well but fails when a wide landscape image is uploaded. in this case the resulting thumbnail is not square.
also the thumbnails appear a bit 'zoomed in' and do not really show off the image content too well.
I have tried using commands such as:
convert... -thumbnail 140^> -gravity center -crop 140x140+0+0
the idea being to initially create a thumbnail that is at least 140px along its smallest side (?), then crop the long side/middle part to create the square thumbnail.
but this does not work - on either 6.3.5 or 6.7.4 - i still get a non-square thumbnail on wide uploaded images.
in summary, how do i create a square thumbnail based on resizing the shortest side of an uploaded image?? obviously preserving the aspect ratio.
can anyone advise if this is possible, and give me some commands that will do this??
any information is welcome. thank you.
tim ecott.
Resizing images based on shortest side...
-
- Posts: 2
- Joined: 2012-01-24T15:47:13-07:00
- Authentication code: 8675308
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resizing images based on shortest side...
6.3.5 is too old for ^ and the > will only create a thumnail if the image is larger than 140
try on the newer version (using either quotes or an escape for ^ and >)
convert... -thumbnail '140x140^>. -gravity center -crop 140x140+0+0 +repage
This works fine for me on IM 6.7.4.9 Q16 Mac OSX Snow Leopard
convert logo: -thumbnail '140x140^>' -gravity center -crop 140x140+0+0 +repage logo_thumb.png
try on the newer version (using either quotes or an escape for ^ and >)
convert... -thumbnail '140x140^>. -gravity center -crop 140x140+0+0 +repage
This works fine for me on IM 6.7.4.9 Q16 Mac OSX Snow Leopard
convert logo: -thumbnail '140x140^>' -gravity center -crop 140x140+0+0 +repage logo_thumb.png
-
- Posts: 2
- Joined: 2012-01-24T15:47:13-07:00
- Authentication code: 8675308
Re: Resizing images based on shortest side...
thank you for your reply. using the new version of IM, AND getting the right format for shifting the ^ and > made all the difference.
now i am using this function:
function image_convert($action, $source, $dest) {
$IM_path = "d:\\ImageMagick-6.7.4-Q16\\convert.exe"; // Full IM path here
exec("$IM_path $action \"$source\" \"$dest\""); //Execute ImageMagick
return;
}
and this command:
$action_string = " -thumbnail \"140x140^>\" -gravity center -crop 140x140+0+0 +repage ";
image_convert($action_string,$source,$dest); //ImageMagick will create 140px square thumbnail
the key is getting the shifting right in the command line!!
i will now upgrade production servers to the new version of IM.
thank you for your help.
now i am using this function:
function image_convert($action, $source, $dest) {
$IM_path = "d:\\ImageMagick-6.7.4-Q16\\convert.exe"; // Full IM path here
exec("$IM_path $action \"$source\" \"$dest\""); //Execute ImageMagick
return;
}
and this command:
$action_string = " -thumbnail \"140x140^>\" -gravity center -crop 140x140+0+0 +repage ";
image_convert($action_string,$source,$dest); //ImageMagick will create 140px square thumbnail
the key is getting the shifting right in the command line!!
i will now upgrade production servers to the new version of IM.
thank you for your help.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Resizing images based on shortest side...
The alternative for '^' resize flag is still in IM examples in...
http://www.imagemagick.org/Usage/resize/#space_fill
The method needed to handle BOTH landscape and Portrait images however needs 2-3 resize steps to achieve the result.
http://www.imagemagick.org/Usage/resize/#space_fill
The method needed to handle BOTH landscape and Portrait images however needs 2-3 resize steps to achieve the result.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/