Return to Snippet

Revision: 18356
at September 29, 2009 04:11 by zemin


Initial Code
<?php 
 
function createThumb($width,$height,$quality,$filename,$newfilename){ 
//@author: zemin 
if (file_exists($newfilename) || is_file($newfilename)) return false; 
$info = getimagesize($filename); 
$types = array( 
1 => 'gif', 
2 => 'jpeg', 
3 => 'png'
); 
if (!$types[$info[2]]) return false; 
$ratio_orig = $info[0]/$info[1]; 
if ($width/$height > $ratio_orig) { 
$width = $height*$ratio_orig; 
} else { 
$height = $width/$ratio_orig; 
} 
eval(' 
$image_p = imagecreatetruecolor($width, $height); 
$image = imagecreatefrom'.$types[$info[2]].'($filename); 
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $info[0], $info[1]); 
$result = image'.$types[$info[2]].'($image_p, $newfilename, $quality); 
'); 
return $result; 
} 
 
var_dump(createThumb(500,300,100,'files/test.jpg','test/newThumb.jpg')); 
?>

Initial URL

                                

Initial Description

                                

Initial Title
GD Create Image Thumb

Initial Tags
php, image, function

Initial Language
PHP