Page 1 of 1

GD Library Help...

Posted: Thu Apr 03, 2003 4:04 pm
by bonkers
This script I made is supposed to take an image via ... me=sue.jpg 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...

Code: Select all

<? // 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]);



Posted: Fri Apr 04, 2003 2:05 am
by pootergeist
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.

Posted: Fri Apr 04, 2003 12:10 pm
by bonkers
I'm getting an error message now.

Code: Select all

<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>

Posted: Sat Apr 05, 2003 10:30 am
by pootergeist
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.

Posted: Sat Apr 05, 2003 10:43 am
by bonkers 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

Posted: Sun Apr 06, 2003 3:11 am
by pootergeist
I can tell from your parse returns that $imagefilename is returning a value of 'resource id #1' ---- get that working first.