JOE DESIGNS

A dev shop in Albuquerque New Mexico.

Using ImageMagick & PHP to Resize / Crop Images to flickr style squares.

Filed under "general" on 3/24/08

Here is a quick snippet of code I use frequently to get the flickr style square cropped thumbnails using php and imagemagick.

<?php

function sqThm($src,$dest,$size=75){
   
   list($w,$h) = getimagesize($src);

   if($w > $h){
      exec("convert ".$src." -resize x".$size." -quality 100 ".$dest);
   }else{
      exec("convert ".$src." -resize ".$size." -quality 100 ".$dest);
   }

   exec("convert ".$dest." -gravity Center -crop ".$size."x".$size."+0+0 ".$dest);

}

sqThm('gfx/tree.jpg','gfx/tree_squared.jpg');

?>