PHP调整图片大小(宽度3024px高度4032px)

时间:2019-05-23 15:46:56

标签: php image-processing imagemagick gd

我正在尝试从iPhone上载宽度为3024高度为4032的图像。我想将其尺寸调整为800x600px,可以正确调整尺寸,但是问题是我的垂直(人像)图像显示为水平(横向)。输出示例https://prnt.sc/nsfkid

// The file
$filename = 'test.jpg';

// Set a maximum height and width
$width = 800;
$height = "";
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output[enter image description here][1]
imagejpeg($image_p, null, 100);

0 个答案:

没有答案