Create a Thumbnail





29
Date Submitted Tue. Nov. 8th, 2005 4:53 AM
Revision 1 of 1
Beginner jelena
Tags Image | PHP | Thumbnail
Comments 8 comments
Create a Thumbnail
function image_create_thumb($filename, $width, $height)
{
        list($image["Width"], $image["Height"], $image["Type"]) = getimagesize($filename);

        if($image["Type"] == IMG_JPG || $image["Type"] == IMG_JPEG)
        {
                $im_image = ImageCreateFromJPEG($filename);
        }
        if($image["Type"] == IMG_GIF)
        {
                $im_image = ImageCreateFromGIF($filename);
        }
        if($image["Type"] == IMG_PNG)
        {
                $im_image = ImageCreateFromPNG($filename);
        }

        if($image["Width"] > $image["Height"])
        {
                $scale = $width / $image["Width"];
                $thumb_width = $width;
                $thumb_height  = floor($image["Height"]*$scale);
        }
        else
        {
                $scale = $height / $image["Height"];
                $thumb_height = $height;
                $thumb_width  = floor($image["Width"]*$scale);
        }

        $im_thumb = @ImageCreateTrueColor($thumb_width, $thumb_height) or die("Cannot Initialize new GD image stream");

        ImageCopyResized($im_thumb,$im_image,0,0,0,0,$thumb_width,$thumb_height,$image["Width"],$image["Height"]);

        ImageDestroy($im_image);
        ImagePNG($im_thumb, $filename);
        ImageDestroy($im_thumb);

        return true;
}//image_create_thumb($filename, $width, $height)

Comments

Comments Switch
Wed. Aug. 30th, 2006 8:31 AM    Helper dohpaz
Comments im lost
Sun. Mar. 11th, 2007 10:43 PM    Newbie kayd
Comments Disregard this.
Thu. Mar. 22nd, 2007 7:27 PM    Newbie circusbred
Comments Nice..
Thu. Jun. 19th, 2008 3:21 PM    Newbie Catalin
Comments Nice..
Thu. Jun. 19th, 2008 3:23 PM    Newbie Catalin
Comments Commentary?
Wed. Mar. 15th, 2006 12:19 AM    Helper Scriptsentials
  Comments Comments Needed
Wed. Oct. 11th, 2006 10:21 AM    Helper Thomas
    Comments agreed
Sun. Mar. 11th, 2007 10:44 PM    Newbie kayd

Voting