Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: GD Library

  1. #1
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    Thanked 0 Times in 0 Posts

    GD Library

    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

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    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

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,067
    Thanks
    2
    Thanked 319 Times in 311 Posts
    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
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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) :




    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

    PHP Code:

    <?

    // 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$image00$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
    Last edited by lpeek; 06-02-2007 at 06:57 PM.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,067
    Thanks
    2
    Thanked 319 Times in 311 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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

  • #7
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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...

  • #8
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    You would want something like this

    index.php
    Code:
    <img src="./generateimage.php?i=./images/hello.jpg" />
    generateimage.php
    PHP Code:
    $image imagecreatefromjpeg($_GET['i']);

    // Do some stuff

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •