网上找来的一个生成缩略图的函数
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract the release file under
protected/extensions
- extension=php_gd2.dll
Usage ¶
See the following code example:
...
$im = null;
$imagetype = strtolower($model->image->extensionName)
if($imagetype == 'gif')
$im = imagecreatefromgif($path);
else if ($imagetype == 'jpg')
$im = imagecreatefromjpeg($path);
else if ($imagetype == 'png')
$im = imagecreatefrompng($path);
CThumb::resizeImage (
$im,100, 100,
'd:\upload\head\\thumb\\test' . $model->image->extensionName, $model->image->extensionName );
...
Change Log ¶
December 17, 2009 ¶
- Initial release.
Thanks
it works,but there some question
1.can only change to jpg?if wan't change png gif,should add
a.in controller
imagesavealpha($im,TRUE);//add for png CThumb::resizeImage ( $im,100, 100, 'd:\upload\head\\thumb\\test' . $model->image->extensionName, $model->image->extensionName );
b.in CThumb.php lin 41 change to:
... if($filetype=='png'){ imagepng ( $newim, $name ); imagedestroy ( $newim ); }elseif($filetype=='gif') { imagegif ( $newim, $name ); imagedestroy ( $newim ); }else{ imagejpeg ( $newim, $name ); imagedestroy ( $newim ); } } else {//if thumb size > real size,create mirror if($filetype=='png'){ imagepng ( $im, $name ); imagedestroy ( $im ); }elseif($filetype=='gif') { imagegif ( $im, $name ); imagedestroy ( $im ); }else{ imagejpeg ( $im, $name ); imagedestroy ( $im ); } }
2.if one of the width or height > real size.maybe report error:"undefine $resizewidth_tag",so can add in the head line 6:
$resizewidth_tag=false; $resizeheight_tag = false;
above all ,if it not correct,please report out.and other thumb ext like this: http://www.yiiframework.com/extension/ephpthumb/ has more function and easy to use.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.