function __getThumbnailResource($imgSrc, $thumbnail_width, $thumbnail_height) {
$arrInfo = getimagesize($imgSrc);
$width_orig = $arrInfo[0];
$height_orig = $arrInfo[1];
$lmime = strtolower($arrInfo['mime']);
if (strpos($lmime, 'gif') !== false) {
$myImage = imagecreatefromgif($imgSrc);
} elseif (strpos($lmime, 'png') !== false) {
$myImage = imagecreatefrompng($imgSrc);
} else {
$myImage = imagecreatefromjpeg($imgSrc);
}
if ($thumbnail_height == $height_orig && $thumbnail_width == $width_orig) {
return $myImage;
}
$ratio_orig = $width_orig/$height_orig;
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
$new_height = $thumbnail_width/$ratio_orig;
$new_width = $thumbnail_width;
} else {
$new_width = $thumbnail_height*$ratio_orig;
$new_height = $thumbnail_height;
}
$x_mid = $new_width/2; //horizontal middle
$y_mid = $new_height/2; //vertical middle
$process = imagecreatetruecolor(round($new_width), round($new_height));
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
imagedestroy($process);
imagedestroy($myImage);
return $thumb;
}
function cropImage($imgSrc, $arrSize, $imgTarget = null) {
$thumbnail_width = $arrSize[0]; $thumbnail_height = $arrSize[1];
if (!$imgTarget) $imgTarget = basename($imgSrc);
$newThumb = CroppedThumbnail($imgSrc, $thumbnail_width, $thumbnail_height);
$ext = substr($imgTarget, -4);
if ($ext == '.gif') {
imagegif($newThumb, $imgTarget);
} elseif ($ext == '.jpg') {
imagejpeg($newThumb, $imgTarget);
} else {
return false;
}
return $imgTarget;
}
createThumbnail("3372.jpg",64,64,'x.gif');
//Create the thumbnail
#$newThumb = CroppedThumbnail("C:\\Documents and Settings\\LNV\\Desktop\\2.gif",25,25);
// And display the image...
#header('Content-type: image/jpeg');
#imagejpeg($newThumb);
?>
Title:
crop and resize image to create thumbnail or do sth
Description:
function __getThumbnailResource($imgSrc, $thumbnail_width, $thumbnail_height) { $arrInfo = getimagesize($imgSrc); $width_orig = $arr...
...
Rating:
4