Log in

View Full Version : PHP Image Thumbnail Script Not Working



benslayton
05-23-2007, 03:31 AM
http://www.partdigital.com/tutorials/gd-thumbnail/

I cant get this script to work on my server I have GD installed. I think I am doing something wrong. Can some one put the whole scrip together for me...

mbrodin
05-24-2007, 07:19 AM
http://www.partdigital.com/tutorials/gd-thumbnail/

I cant get this script to work on my server I have GD installed. I think I am doing something wrong. Can some one put the whole scrip together for me...

Hi!

Heres the script!



<?php

//Your Image
$imgSrc = "image.jpg";

//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);

//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefromjpeg($imgSrc);

///--------------------------------------------------------
//setting the crop size
//--------------------------------------------------------
if($width > $height) $biggestSide = $width;
else $biggestSide = $height;

//The crop size will be half that of the largest side
$cropPercent = .5;
$cropWidth = $biggestSide*$cropPercent;
$cropHeight = $biggestSide*$cropPercent;


//getting the top left coordinate
$c1 = array("x"=>($width-$cropWidth)/2, "y"=>($height-$cropHeight)/2);

//--------------------------------------------------------
// Creating the thumbnail
//--------------------------------------------------------
$thumbSize = 60;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $c1['x'], $c1['y'], $thumbSize, $thumbSize, $cropWidth, $cropHeight);

//--------------------------------------------------------
// Creating the lines
//--------------------------------------------------------
$lineWidth = 1;
$margin = 0;
$green = imagecolorallocate($thumb, 193, 252, 182);

for($i=0; $i<2; $i++){
//left line
imagefilledrectangle($thumb, $margin, $margin, $margin+$lineWidth, $thumbSize-$margin, $green);
//right line
imagefilledrectangle($thumb, $thumbSize-$margin-$lineWidth, $margin, $thumbSize-$margin, $thumbSize-$margin, $green);
//topLine
imagefilledrectangle($thumb, $margin, $margin, $thumbSize-$margin-$lineWidth, $margin+$lineWidth, $green);
//bottom line
imagefilledrectangle($thumb, $margin, $thumbSize-$margin-$lineWidth, $thumbSize-$margin-$lineWidth, $thumbSize-$margin,$green);
$margin+=4;
}

//final output
header('Content-type: image/jpeg');
imagejpeg($thumb);
imagedestroy($thumb);

?>


Best regards,
mbrodin

hanji
05-25-2007, 09:26 PM
http://www.partdigital.com/tutorials/gd-thumbnail/

I cant get this script to work on my server I have GD installed. I think I am doing something wrong. Can some one put the whole scrip together for me...

What is exactly breaking? Do you have any error messages, etc? Are you using jpg and gifs?

Thanks!
hanji

benslayton
05-28-2007, 04:46 PM
No i figured out that in every box that he had with code there were some "<?Php" starting tags and no ending tags. I just had to take out all the tags and have one at the top of the document and one at the bottom of the document.