...

View Full Version : GD Library



lpeek
06-02-2007, 07:17 PM
Hey im setting up a website. and im using some php fuctions that require the GD Library. but its not working. obviously im guessing the GD Library isnt installed, but i was wondering... because ive been trying to find out about it all and havent had much luck...

is the GD library something i need to install as it upload it to my website?

is it something every use needs on their computer?

or is it something i need to contact my server/host to install ?

any help would be greatly appreciated.

if you want to have a look at the site... see what gobblede-gook its throwing at me when i run the script have a look at: www.jrevolution.net

Thanks

rafiki
06-02-2007, 07:22 PM
show your php info and see if gd is installed and if its currently running
as for the gobblede-gook your site shows me the txt "www.jrevolution.net" as an image? is this what you wanted? show us code aswell

CFMaBiSmAd
06-02-2007, 07:35 PM
If you have shared hosting, the GD library is probably installed and loaded, but the reason your web site looks like that is because you are not placing the image on your page using proper HTML tags - http://w3schools.com/html/html_images.asp

lpeek
06-02-2007, 07:53 PM
Ah sorry :)

CFM: yes im using correct HTML tags, <img src="URL"> n all that.

RAFIKI: no i didnt get text as the image, and its not what i wanted lol. here is what I get (and tested on other computers, same result) :


http://www.jrevolution.net/troubleshoot.jpg

heres the code snipped for the image section:

this is all the code. i would HOPE it would display 3 images... cropped from a larger image into a square, 200 by 200, then resized to 100 by 100 with text below.

There are some <table><tr> and <td> tags missing i know but i took those out to make it shorter as thats not the problem we're trying to solve :)




<?

// TOP VIEWED BANDS

$topband = mysql_query("SELECT * FROM bands ORDER by views DESC LIMIT 3 ") or die(mysql_error());
$topband2 = mysql_num_rows($topband);

//START LOOP

for ($i = 0; $i < $topband2; $i++) {

$row = mysql_fetch_array($topband);

// CROP AND RESIZE IMAGES

$img = $row['pic']; // get pic url
list($width, $height) = getimagesize($img); // img width n height

$image = imagecreatefromjpeg($img);

if($width > $height) $biggestSide = $width; // set position and size to crop
else $biggestSide = $height;

$cropWidth = $biggestSide*.5;
$cropHeight = $biggestSide*.5;

$c1 = array("x"=>($width-$cropWidth)/2, "y"=>($height-$cropHeight)/2);

//crop & thumbnail the image

$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize); // size set to 100 square
imagecopyresampled($thumb, $image, 0, 0, $c1['x'], $c1['y'], $thumbSize, $thumbSize, $cropWidth, $cropHeight);

header('Content-type: image/jpeg');

//FINISH IMAGE CROP - START DISPLAY

echo '<a href="'.$musicpath.'band.php?id='.$row['id'].'">
<img src="'.imagejpeg($thumb).'">
'.$row['name'].'</a>';

imagedestroy($thumb);

} //END LOOP

?>



Thanks

CFMaBiSmAd
06-02-2007, 08:04 PM
The src parameter of the <img src="..." alt=""> tag requires a URL. You cannot output image data directly on a web page. Browsers don't work that way. They fetch the image at the given URL separately.

lpeek
06-02-2007, 08:58 PM
yeah, i know that bit :P

but im just trying to figure out what i need to do to fix my problem im having... i know what the code does, but it didnt work by outputing the image just as:

imagejpeg($thumb);

which is what it told me to do in a code manual i read, so i thought maybe it would work as the src section of the img tag as i know some php functions work that way.

like:

<img src="'.imagejpeg($thumb).'">

i know a URL goes in the src. thats just basic html knowledge :P

any help on why the actual code isnt working would be greatly appreciated.

thanks for your help

lpeek
06-02-2007, 09:20 PM
right.... ive sorted it a little... i missreadthe second value where it is NULL

imagejpeg($thumb,NULL,75)

when NULL is given the raw image stream is output. instead of an actual image if u i specify an actual location:

imagejpeg($thumb,'http://www.jrevolution.net/images/band_pics/thumbs/pic.jpg',75)

but now the problem im having is:

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://www.jrevolution.net/images/band_pics/thumbs/Dir En Grey.jpg' for writing in /usr/home1/jrevolu/public_html/index.php on line 122

I have CHMODD'ed the directory 'thumbs' to 777 but no help...

mr e
06-02-2007, 09:27 PM
You would want something like this

index.php


<img src="./generateimage.php?i=./images/hello.jpg" />


generateimage.php


$image = imagecreatefromjpeg($_GET['i']);

// Do some stuff

header('Content-type: image/jpeg');
imagejpeg($image);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum