|
<?php
/*
Created by : Mohammad Dayyan
Mds_soft@yahoo.com
1387/5/15
*/
function thumbnail_image($original_file_path, $new_width, $new_height, $save_path="")
{
$imgInfo = getimagesize($original_file_path);
$imgExtension = "";
switch ($imgInfo[2])
{
case 1:
$imgExtension = '.gif';
break;
case 2:
$imgExtension = '.jpg';
break;
case 3:
$imgExtension = '.png';
break;
}
if ($save_path=="") $save_path = "thumbnail".$imgExtension ;
// Get new dimensions
list($width, $height) = getimagesize($original_file_path);
// Resample
$imageResample = imagecreatetruecolor($new_width, $new_height);
if ( $imgExtension == ".jpg" )
{
$image = imagecreatefromjpeg($original_file_path);
}
else if ( $imgExtension == ".gif" )
{
$image = imagecreatefromgif($original_file_path);
}
else if ( $imgExtension == ".png" )
{
$image = imagecreatefrompng($original_file_path);
}
imagecopyresampled($imageResample, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if ( $imgExtension == ".jpg" )
{
imagejpeg($imageResample, $save_path);
}
else if ( $imgExtension == ".gif" )
{
imagegif($imageResample, $save_path);
}
else if ( $imgExtension == ".png" )
{
imagepng($imageResample, $save_path);
}
}
?>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.