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

Php 旋转后如何获得图像的宽度和高度?,php,gd,php-gd,Php,Gd,Php Gd,在PHP中使用imagerotate()旋转图像后,如何获得图像的宽度和高度 这是我的密码: <?php // File and rotation $filename = 'test.jpg'; $degrees = 180; // Content type header('Content-type: image/jpeg'); // Load $source = imagecreatefromjpeg($filename); // Rotate $rotate = imagerot

在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。 使用


相反。

不,这样不行。在这里发布之前我已经试过了:)那么如果它不起作用,它会做什么呢?它是否出错,是否使服务器崩溃,是否返回不正确的值?如果将图像旋转180度,则图像的宽度和高度不应改变。在旋转图像之前,您是否可以使用它来获取图像的高度和宽度?它表示“警告:getimagesize()期望参数1为字符串”。php文档中明确指出,它必须传递到图像的路径,不是图像object@aslamdoctor-您知道执行
$source=imagecreatefromjpeg($filename)时使用的
$filename
的值。。。如果在
$data=getimagesize($filename)中使用相同的
$filename
值,您会得到什么根据BeatAlex的建议?这是问题的正确答案
getimagesize()
用于旋转前原始文件的尺寸
imagesx()
imagesy()
用于旋转后的尺寸或处理过的文件。
$width = imagesx($rotate);
$height = imagesy($rotate);