Convert Imagemagick code to GD

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
overflo
Forum Newbie
Posts: 1
Joined: Sun May 04, 2008 11:40 pm

Convert Imagemagick code to GD

Post 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);
 
Post Reply