上传,调整大小并获取新图像的尺寸

时间:2018-12-08 08:43:46

标签: php image

输入类型文件-上传图片

$arr = $_FILES['inpfile'];
$filename = $arr['name'];
$tempname = $arr['tmp_name'];

$arr = getimagesize($tempname);
$origw = $arr[0]; // original width
$origh = $arr[1]; // original height

if ($mime == 'image/jpeg') {$newimg = imagecreatefromjpeg($tempname);}
elseif ($mime == 'image/png') {$newimg = imagecreatefrompng($tempname);}
elseif ($mime == 'image/gif') {$newimg = imagecreatefromgif($tempname);}

if($origw > 960) {
    $newimg = imagescale($newimg, 960);
}

现在我需要新图像的尺寸:

$arr = getimagesize($newimg);
$endw = $arr[0];
$endh = $arr[1];

警告:

getimagesize() expects parameter 1 to be string, resource given

有帮助吗?

1 个答案:

答案 0 :(得分:0)

要获取图像的宽度和高度资源(在您的情况下,$newimg具有资源类型),可以使用imagesx / { {3}}分别起作用:

$endw = imagesx($newimg);
$endh = imagesy($newimg);