Showing posts with label Create thumbnail image in php. Show all posts
Showing posts with label Create thumbnail image in php. Show all posts

Wednesday, July 10, 2013

Create thumbnail image in php

function make_thumb($src, $dest,$desired_height, $desired_width) {

    /* read the source image */
    $source_image = imagecreatefromjpeg($src);
    $width = imagesx($source_image);
    $height = imagesy($source_image);
   
    /* find the "desired height" of this thumbnail, relative to the desired width  */
    //$desired_height = floor($height * ($desired_width / $width));
   
    /* create a new, "virtual" image */
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);
   
    /* copy source image at a resized size */
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
   
    /* create the physical thumbnail image to its destination */
    imagejpeg($virtual_image, $dest);
}


calling 
@move_uploaded_file($_FILES['product_image1']['tmp_name'], 'uploads/'.$random_digit.$_FILES['product_image1']['name']);
echo make_thumb('uploads/'.$random_digit.$_FILES['product_image1']['name'],'uploads/'.$random_digit.$_FILES['product_image1']['name'],626,476);



Popular Posts