如何检查图像是否为PNG,GIF,TIFF和JPG,如果是这样,请创建缩略图并将其保存到拇指文件中。如何使用PHP检查并查看图像扩展?
到目前为止,我可以检查并保存JPEG图像。
以下是下面的代码。
<?php
//Name you want to save your file as
$save = 'members/3/images/thumbs/thumb-pic.jpg';
$file = 'members/3/images/pic.jpg';
echo "Creating file: $save";
list($width, $height) = getimagesize($file) ;
if ($width >= 180){
$modwidth = 180;
$modheight = ((180.0/$width) * $height);
} else {
$modwidth = $width;
$modheight = $height;
}
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
// Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%
imagejpeg($tn, $save, 100) ;
?>
如何将此代码添加到我的代码中? – ImAGe 2009-11-13 07:49:14
依靠imagick生成缩略图这样简单的东西简直就是一个粗略的...我参加过的主持人并不多。 – brianreavis 2009-11-13 07:51:16