0

如果使用 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

4

0 回答 0