Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

GD Library Help...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

GD Library Help...

Postby bonkers » Thu Apr 03, 2003 4:04 pm

This script I made is supposed to take an image via http://site.com/ImageThumbnail.php?/Ima ... 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]);

ImageJpeg($ThumbnailDestination);


?>
bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

Postby pootergeist » Fri Apr 04, 2003 2:05 am

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 - http://www.phpclasses.org/browse.html/package/1007.html (online demo not accessible though) and just use a 650x144px base_image for sizing protocols.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby bonkers » Fri Apr 04, 2003 12:10 pm

I'm getting an error message now.

Code: Select all
<br>
<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>
<br>
<b>Warning</b>:  Division by zero in <b>/var/www/html/ImageThumbnail.php</b> on line <b>22</b><br>
<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>

bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

Postby pootergeist » Sat Apr 05, 2003 10:30 am

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.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby bonkers » Sat Apr 05, 2003 10:43 am

Wait...do I have to fopen the file first?

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

gd
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
bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

Postby pootergeist » Sun Apr 06, 2003 3:11 am

I can tell from your parse returns that $imagefilename is returning a value of 'resource id #1' ---- get that working first.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.