GD Library Help...



This script I made is supposed to take an image via and return the same image reduced to 144 x Calculated Width.
Here is the code, something doesn't work. I'll include my notes and everything...

<? // This File will take "$file" and resize it from whatever size it is to 152 width X 114 height
//open image
//make destination image via imagecreatetruecolor()
//Make Proportion. If I want the height to be 114, then I'll make a proportion like this
//    ho/wo = 114/x
//Find size of original 
//resize image avec imagecopyresampled(

// a / b = c / d
// ad = bc
// d = bc/a

// 5/8 = 10/x
header("Content-type: image/jpeg");

$ThumbnailOriginal = $imagecreatefromjpeg("$ImageFileName"); // Opens up the image.

$NewHeight = 144; // Thumbnail Destination Height.

$OriginalSize = getimagesize("$ThumbnailOriginal"); // Get Dimesions of Image.

$NewWidth = ($OriginalSize[0]*$NewHeight)/$OriginalSize[1]; // GetDimesions of Destination Image.

$ThumbnailDestination = $imagecreatetruecolor($NewWidth, $NewHeight);

imagecopyresampled($ThumbnailDestination, $ThumbnailOriginal, $NewWidth, $NewHeight, $OriginalSize[0], $OriginalSize[1], $NewWidth, $NewHeight, $OriginalSize[0], $OriginalSize[1]);


for a start imagecreatefromjpeg should not have a $ at the start as it's a function and not a variable.;

personally I would amend your code and actually save a copy of the thumbnail to the server - if you view that thumb more than once (ie two people view the page or you view the page twice) you are wasting serving resources for no reason.

imagejpeg($ThumbnailDestination, 'newpath/thumb_'.$ThumbnailDestination, 85);

if you want to go further and maybe add some manipulations (eg bevel, drop-shadow, motion_blur, ellipse, overlay, frame, greyscale) you could try the GD2+ class I wrote - (online demo not accessible though) and just use a 650x144px base_image for sizing protocols.
I'm getting an error message now.

<b>Warning</b>:  getimagesize: Unable to open 'Resource id #1' for reading. in <b>/var/www/html/ImageThumbnail.php</b> on line <b>20</b><br>
<b>Warning</b>:  Division by zero in <b>/var/www/html/ImageThumbnail.php</b> on line <b>22</b><br>
<b>Fatal error</b>:  imagecreatetruecolor(): requires GD 2.0 or later in <b>/var/www/html/ImageThumbnail.php</b> on line <b>24</b><br>
well, sounds like $imagefilename is being returned as 'resource id #1' (I assume from a badly formed mysql query or that you left the / in the url after the ? ) - try echoing that alone to see if it holds your proper image pointer - if not, start debugging there. I have to fopen the file first?

here's my GD library info...if this helps:

GD Support enabled
GD Version 1.6.2 or higher
FreeType Support enabled
FreeType Linkage with freetype
T1Lib Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
I can tell from your parse returns that $imagefilename is returning a value of 'resource id #1' ---- get that working first.