【发布时间】:2011-02-10 18:36:48
【问题描述】:
我目前正在使用一个 php 脚本,它根据最大宽度和高度创建缩略图。但是,我希望它始终创建方形图像并在需要时裁剪图像。
这是我现在使用的:
function makeThumb( $filename, $type ) {
global $max_width, $max_height;
if ( $type == 'jpg' ) {
$src = imagecreatefromjpeg("blocks/img/gallery/" . $filename);
} else if ( $type == 'png' ) {
$src = imagecreatefrompng("blocks/img/gallery/" . $filename);
} else if ( $type == 'gif' ) {
$src = imagecreatefromgif("blocks/img/gallery/" . $filename);
}
if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
$newW = $oldW * ($max_width / $oldH);
$newH = $max_height;
} else {
$newW = $max_width;
$newH = $oldH * ($max_height / $oldW);
}
$new = imagecreatetruecolor($newW, $newH);
imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
if ( $type == 'jpg' ) {
imagejpeg($new, 'blocks/img/gallery/thumbs/'.$filename);
} else if ( $type == 'png' ) {
imagepng($new, 'blocks/img/gallery/thumbs/'.$filename);
} else if ( $type == 'gif' ) {
imagegif($new, 'blocks/img/gallery/thumbs/'.$filename);
}
imagedestroy($new);
imagedestroy($src);
}
我将如何改变它来完成我想要的(大拇指)?
提前致谢。
【问题讨论】:
-
真的像
plz-send-me-the-code问题。
标签: php image thumbnails