Page 1 of 1

Convert Imagemagick code to GD

Posted: Sun May 04, 2008 11:48 pm
by overflo
Hi

I'm in dire straits. Just spent ages putting together a dynamic site, uploaded and have found out that hosts have disabled exec functions due to security problems. I am so far very happy otherwise with hosts (just had a very bad experience with previous) the trouble is, as I also work and am primary carer for disabled son I don't have the time to learn the differences between Imagemagick and GD.
If anyone could start me off in the right direction by converting the following code (that gets the image, finds shortest edge and resizes so shortest edge is 300 the crops to 300x300) I will be eternally grateful.

Cheers

Code: Select all

 
$img  = "pathtoimage/image.jpg";
$size = GetImageSize($img);
$dim  = "300x300+0+0"; 
 echo $size[0] . " " . $size[1];
    // Wide Image
    if($size[0] > $size[1]) {  
        $thumbnail_height = 300;  
        $thumbnail_width = (int)(300 * $size[0] / $size[1]);  
    }  
    
    // Tall Image
    else{
         $thumbnail_height = (int)(300 * $size[1] / $size[0]);
         $thumbnail_width = 300;
    }
        
$mogrify = "pathtimagemagick/mogrify -geometry";
$crop    = "pathtimagemagick/mogrify -gravity Center -crop";
system("$mogrify $thumbnail_heightx$thumbnail_width $img", $exec_retval);
system("$crop $dim $img", $exec_retval);