ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

Image manipulation with PHP & the GD library, Part 2

(Page 4 out of 3)

« Previous: Watermarking Images & Conclusion



5 Responses to “Image manipulation with PHP & the GD library, Part 2”

  1. vish Says:

    Hi
    i want to resample an image to half its original size but there are not properly done
    using the following code so please help me for solving the code :

    0) {
    $row = mysql_fetch_array ($result);
    $percent = 0.5; //ex

    $image_type = $row[”image_type”];
    $image = $row[”image”];
    $image_name = $row[”image_name”];

    header(’Content-type: $image_type’);

    // Get new dimensions
    $width = imagesx($image);
    $height = imagesx($image);

    $new_width = $width * $percent;
    $new_height = $height * $percent;

    // Resample
    $image_p = imagecreatetruecolor($new_width,$new_height);
    $imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    // Output
    header(’Content-type: image/jpeg’);
    imagejpeg($image_p);

    Regards ,
    vish

    }
    ?>

  2. Harry D Says:

    Hi vish,

    while watching your code I found header(’Content-type: $image_type’); and header(’Content-type: image/jpeg’);.
    You can only send one header at once, not two. Just use the last one to make sure everything gets done before you put the resized image on screen.

    Then, if you need to resize gif and png you need another header, so implement a switch case i.e. to get the type and use the right functions for these types.

    best regards,

    Harald Doderer
    Director Emedian Ltd.
    www.emedian.net

  3. Ramesh N Sharma Says:

    short and useful tutorial

  4. Jawad Shuaib Says:

    Thank you so much for this tutorial. This is exactly what I was looking for :) Thank you!

  5. intekhab alam Says:

    it help me to solve my problem so thanyou very much.

Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. Introduction & Resizing Images
  2. Online Thumbnail Creator
  3. Watermarking Images & Conclusion
Bookmark Article
Download Article
PDF
Download this article as a PDF file