如何檢查圖像是否爲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