PHP function for Resizing and/or Cropping images with GD

You may also like...

4 Responses

  1. kimberly says:

    Sir… can this code make faster for website load..
    how about using CSS ? i hope you know what I mind and i need your answer. So, i follow this post by my email. I ll be back again..

    thanks

  2. Mic Go Mac says:

    Thanks for the code. In my case I need to give a fixed height rather than width.
    I added some codes there after line 32:

    } elseif (!$w && $h) {
    $ratio = $h / $source_height;
    $temp_width = $source_width * $ratio;
    $temp_height = $h;

    $desired_gdim = imagecreatetruecolor($temp_width, $temp_height);
    imagecopyresampled(
    $desired_gdim,
    $source_gdim,
    0, 0,
    0, 0,
    $temp_width, $temp_height,
    $source_width, $source_height
    );

    • atomiku says:

      Thank you very much for your contribution, when I have some time I will update the code on the post with your update and also update the function to support PNG transparency, unless you can fix this for me. At the moment, if you use this function to resize a PNG, the cropped/resized version will have a white or black background to it. I haven’t had time to look into this yet.

  3. boduk says:

    this is working good

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>