SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to test gd graphic library?

    I have installed gd graphic library on a linux pc, who could tell me how to check if the installing is right or not? If there are some sample php code using gd library, I could put it on my pc to see if gd library works or not. Thanks!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,195
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)
    Here are a couple of examples you can try:
    PHP Code:
    <?php
    // Set the path to the image to resize
    $input_image "House.jpg";
    // Get the size of the original image into an array
    $size getimagesize$input_image );
    // Set the new width of the image
    $thumb_width "200";
    // Calculate the height of the new image to keep the aspect ratio
    $thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );
    // Create a new true color image in the memory
    $thumbnail ImageCreateTrueColor$thumb_width$thumb_height );
    // Create a new image from file 
    $src_img ImageCreateFromJPEG$input_image );
    // Create the resized image
    ImageCopyResampled$thumbnail$src_img0000$thumb_width$thumb_height$size[0], $size[1] );
    // Save the image as resized.jpg
    ImageJPEG$thumbnail"resized.jpg" );
    // Clear the memory of the tempory image 
    ImageDestroy$thumbnail );
    ?> 
    <img src="resized.jpg">
    PHP Code:
    <?php
    // Create a new image in the memory from the file 
    $png_image imagecreatefrompng"input.png" );
    // Save the image as output.jpg
    imagejpeg$png_image"output.jpg" );
    // Clear the memory of the tempory image 
    imagedestroy$png_image );
    ?> 
    <img src="output.jpg">
    Last edited by Rubble; Apr 27, 2009 at 09:17. Reason: Added the image tags

  4. #4
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much!


Bookmarks

Posting Permissions

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