一些使用考虑,你想使一个缩略图并保存它,你可以实现方便的调整大小功能,如下所示:
<?php
function resize($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality){
$ext1 = explode(".",trim($sourcefile));
$ext = strtolower(trim(array_slice($sext1,-1)));
switch($ext):
case 'jpg' or 'jpeg':
$img = imagecreatefromjpeg($sourcefile);
break;
case 'gif':
$img = imagecreatefromgif($sourcefile);
break;
case 'png':
$img = imagecreatefrompng($sourcefile);
break;
endswitch;
$width = imagesx($img);
$height = imagesy($img);
if ($width > $height) {
$newwidth = $thumbwidth;
$divisor = $width/$thumbwidth;
$newheight = floor($height/$divisor);
}
else {
$newheight = $thumbheight;
$divisor = $height/$thumbheight;
$newwidth = floor($width/$divisor);
}
// Create a new temporary image.
$tmpimg = imagecreatetruecolor($newwidth, $newheight);
// Copy and resize old image into new image.
imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Save thumbnail into a file.
switch($ext):
case 'jpg' or 'jpeg':
$makeimg = imagejpeg($tmpimg, $endfile, $quality);
break;
case 'gif':
$makeimg = imagegif($tmpimg, $endfile, $quality);
break;
case 'png':
$makeimg = imagepng($tmpimg, $endfile, $quality);
break;
endswitch;
// release the memory
imagedestroy($tmpimg);
imagedestroy($img);
if($makeimg){
chmod($endfile,0755);
return true;
}else{
return false;
}
}
?>
然后,复制完t后他要的文件在我的答案高于此使用我的方法之一,你的服务器,你可以简单地套用功能如下:
$doresize = resize($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality);
echo ($doresize == true ? "IT WORKED" : "IT FAILED");
此功能提供了我很好。我每天将它应用于1000张图像,并且它像魅力一样运作。
是否有权限设置此参数INI?这个警告是否会导致脚本终止? – SimonDowdles 2011-04-08 08:38:23
顺便说一句,你只是想显示这个图像,或者你真的想将它复制到你的服务器? – SimonDowdles 2011-04-08 08:39:09
我没有收到有关INI文件设置的任何警告,它仍然是gdcreate函数的致命错误。 – Dave 2011-04-08 08:52:23