如果使用imagejpeg()函数,图像大小是否受到限制?下面是代码
$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);
我通过从移动相机捕获图像来上传图像,其大小约为3.2MB,我的输出低于输出,但无法从目标路径中找到图像
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
图像的大小或尺寸是否受到限制?
我检查PHP post_max_size是否为128MB