Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2003
    Location
    Pakistan
    Posts
    278

    How to confirm GD is working

    Hello,

    How to confirmed that GD library is installed properly and working,
    Is there anyway to test it ?

    Best Regards
    Hassan

  2. #2
    You can try this test file. Hopefully the formatting will be ok in the forum.

    PHP Code:
    <?php

    // GD test page

    // set the HTTP header type to PNG
    header("Content-type: image/png"); 

    // set the width and height of the new image in pixels
    $width 350;
    $height 360;

    // create a pointer to a new true colour image
    $im ImageCreateTrueColor($width$height);

    // switch on image antialising if it is available
    ImageAntiAlias($imtrue);

    // sets background to white
    $white ImageColorAllocate($im255255255); 
    ImageFillToBorder($im00$white$white);

    // define black and blue colours
    $black ImageColorAllocate($im000);
    $blue ImageColorAllocate($im00255);


    function 
    drawDiamond($x$y$width$colour$filled) {
        
    // access the global image reference (the one outside this function)
        
    global $im;

        
    // here we work out the four points of the diamond
        
    $p1_x $x;
        
    $p1_y $y+($width/2);

        
    $p2_x $x+($width/2);
        
    $p2_y $y;

        
    $p3_x $x+$width;
        
    $p3_y $y+($width/2);

        
    $p4_x $x+($width/2);
        
    $p4_y $y+$width;

        
    // now create an array of points to store these four points
        
    $points = array($p1_x$p1_y$p2_x$p2_y$p3_x$p3_y$p4_x$p4_y);

        
    // the number of vertices for our polygon (four as it is a diamond
        
    $num_of_points 4;
        
        if (
    $filled) {
            
    // now draw out the filled polygon
            
    ImageFilledPolygon($im$points$num_of_points$colour);
        }else{
            
    // draw out an empty polygon
            
    ImagePolygon($im$points$num_of_points$colour);
        }
    }

    // now draw the two diamonds
    drawDiamond(12050100$blackfalse);
    drawDiamond(120200100$bluetrue);

    // send the new PNG image to the browser
    ImagePNG($im); 

    // destroy the reference pointer to the image in memory to free up resources
    ImageDestroy($im); 

    ?>

  3. #3
    Join Date
    Dec 2003
    Location
    Pakistan
    Posts
    278
    Nice script, it really helped me to confim it and I tried for png, gif & jpg,
    on png and gif it draw the boxes but when I check for jpg, it asked me to save the file instead of generating image, seems like JPG support is not enabled in GD,

    Can anyone tell me how to enable JPG support into GD,

    I really appriciate your help stephanhughson,

    Thanks
    Best Regards
    Hassan

  4. #4
    I found this script on google that might work for jpg.

    I hadn't tried alerting the other one.

    PHP Code:
     if($_GET["do"] == "jpg") {
    // create the image
    $jpg ImageCreate(200,200);
    $bg ImageColorAllocate($jpg,0,0,0);
    $tx ImageColorAllocate($jpg,255,128,128);
    ImageFilledRectangle($jpg,0,0,200,200,$bg);
    ImageString($jpg,3,70,90,"it works!",$tx);

    // send the image
    header("content-type: image/jpeg");
    ImageJPEG($jpg);
    } elseif(
    $_GET["do"] == "png") {
    // create the image
    $png ImageCreate(200,200);
    $bg ImageColorAllocate($png,0,0,0);
    $tx ImageColorAllocate($png,255,128,128);
    ImageFilledRectangle($png,0,0,200,200,$bg);
    ImageString($png,3,70,90,"it works!",$tx);

    // send the image
    header("content-type: image/jpeg");
    ImageJPEG($png);
    } elseif(
    $_GET["do"] == "src") {
    show_source(__FILE__);
    } else {
    echo 
    'Generate JPG
    '
    ;
    echo 
    'Generate PNG
    '
    ;
    echo 
    'Show Source';
    }
    ?> 
    Found at http://www.nuonce.net/cobalt-howto/1084139367.html


    I uploaded it and it worked for me:

    http://mytestsite-thatisntreal.com/test.php?do=jpg


    I think it downloading jpgs rather than displaying them is probably because you altered the script, maybe something to do with mime settings. Anyway, this one should work.

  5. #5
    Join Date
    Dec 2003
    Location
    Pakistan
    Posts
    278
    I have confirmed it by uploading php info file, I can't see JPG Support under the GD table, thats the main reason.

  6. #6
    Hmm, ok. I guess you mean you confirmed it wasn't working, rather than that it was working.

    I guess you need to ask your host to check it out.

  7. #7
    Join Date
    Sep 2000
    Location
    Alberta, Canada
    Posts
    3,109
    Nice find, Stephen.

    I modified the code a bit, so that the script works, for those that would like to use it.

    Code:
    <?php
    
    if($_GET["do"] == "jpg") {
    // create the image
    $jpg = ImageCreate(200,200);
    $bg = ImageColorAllocate($jpg,0,0,0);
    $tx = ImageColorAllocate($jpg,255,128,128);
    ImageFilledRectangle($jpg,0,0,200,200,$bg);
    ImageString($jpg,3,25,90,"JPG Image - it works!",$tx);
    
    // send the image
    header("content-type: image/jpeg");
    ImageJPEG($jpg);
    } elseif($_GET["do"] == "png") {
    // create the image
    $png = ImageCreate(200,200);
    $bg = ImageColorAllocate($png,0,0,0);
    $tx = ImageColorAllocate($png,255,128,128);
    ImageFilledRectangle($png,0,0,200,200,$bg);
    ImageString($png,3,25,90,"PNG Image - it works!",$tx);
    
    // send the image
    header("content-type: image/jpeg");
    ImageJPEG($png);
    } elseif($_GET["do"] == "src") {
    show_source(__FILE__);
    } else {
    echo '<a href="?do=jpg">Generate JPG</a>
    ';
    echo '<a href="?do=png">Generate PNG</a>
    ';
    echo '<a href="?do=src">Show Source</a>';
    }
    ?>
    PotentProducts.com - for all your Hosting needs
    Helping people Host, Create and Maintain their Web Site
    ServerAdmin Services also available

  8. #8
    Join Date
    Dec 2003
    Location
    Pakistan
    Posts
    278
    My Server admin has recompiled the php with HPG support in GD Library and everything is owrking now.

  9. #9
    Join Date
    Dec 2003
    Location
    Pakistan
    Posts
    278
    My Server admin has recompiled the php with HPG support in GD Library and everything is owrking now.

Posting Permissions

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