如何获得图像旋转后的宽度和高度


How to obtain width and height of image after rotating it?

在PHP中使用imagerotate()旋转图像后,如何获得图像的宽度和高度?

这是我的代码:

<?php
// File and rotation
$filename = 'test.jpg';
$degrees = 180;
// Content type
header('Content-type: image/jpeg');
// Load
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, $degrees, 0);
// Output
imagejpeg($rotate);
// Free the memory
imagedestroy($source);
imagedestroy($rotate);
?>

但在输出之前,我想做的是,我想得到旋转图像的宽度和高度。我该怎么做?

我相信你可以做类似的事情:

$data = getimagesize($filename);
$width = $data[0];
$height = $data[1];

另一种选择是:

list($width, $height) = getimagesize($filename);

imagerotate返回一个图像资源。因此,您不能使用与图像文件一起使用的getimagesize。使用
$width = imagesx($rotate);
$height = imagesy($rotate);

相反。