Php imagejpeg()的限制
如果使用imagejpeg()函数,图像大小是否有任何限制?下面是代码Php imagejpeg()的限制,php,image,imagejpeg,Php,Image,Imagejpeg,如果使用imagejpeg()函数,图像大小是否有任何限制?下面是代码 $tempFileName = $_FILES['upfile']['tmp_name']; $destPath = dirname( __FILE__ ).$ds.$uploadsFolder.$ds; $destFile = $destPath. $_FILES['upfile']['name']; $fileExtension = strtolower(end(e
$tempFileName = $_FILES['upfile']['tmp_name'];
$destPath = dirname( __FILE__ ).$ds.$uploadsFolder.$ds;
$destFile = $destPath. $_FILES['upfile']['name'];
$fileExtension = strtolower(end(explode('.',$_FILES['upfile']['name'])));
if ($fileExtension == "jpeg") {
$fileExtension = "jpg";
} else if ($fileExtension == "png") {
$image = imagecreatefrompng($tempFileName);
imagejpeg($image, $tempFileName, 100);
imagedestroy($image);
$fileExtension = "jpg";
}
$destFile = $destPath . "1." . $fileExtension;
$maxsize = 1024;
$fn = $_FILES['upfile']['tmp_name'];
$size = getimagesize($fn);
$ratio = $size[0]/$size[1]; // width/height
if( $ratio > 1) {
$width = $maxsize;
$height = $maxsize/$ratio;
}
else {
$width = $maxsize*$ratio;
$height = $maxsize;
}
printf("Source:<br/>{$tempFileName}<br/>");
print_r($size);
printf("{$size[0]} x {$size[1]}<br/>");
printf("<br/>Target:<br/>{$destFile}<br/>");
printf("{$width} x {$height} <br/>");
$src = imagecreatefromstring(file_get_contents($fn));
$dst = imagecreatetruecolor($width,$height);
imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]);
imagedestroy($src);
imagejpeg($dst,$destFile); // adjust format as needed
imagedestroy($dst);
图像的大小或尺寸是否有任何限制
我用PHP检查post_max_size是128MB检查目标上的权限directory@BrettGregson谢谢你的评论,但我发现这不是权限问题,这是PHP版本,我将PHP从7降级到5.6,它可以工作。尽管如此,我还是希望有人能帮上忙。
Source:
/tmp/phpfFF3fO
Array ( [0] => 4608 [1] => 2240 [2] => 2 [3] => width="4608" height="2240" [bits] => 8 [channels] => 3 [mime] => image/jpeg ) 4608 x 2240
Target:
/home/learni64/public_html/uploads/1.jpg
1024 x 497.77777777778