0

I am using Imagick to resize images. Before I resize I attempt to get the width and height of the source file. What is happening is that when I use a portrait image, the returned width I get is actually the height and vice versa. It is as if the image has been rotated from portrait to landscape and then the width and height is returned.

My code is below:

$pdfPage = '128K_480x640.jpg';

$im = new imagick($pdfPage);
$im -> setResolution(600, 600);
$im -> setImageFormat('jpg');

$geo = $im->getImageGeometry();
$srcImgWidth = $geo['width'];
$srcImgHeight = $geo['height'];
$srcWHRatio = $srcImgWidth/$srcImgHeight;

echo 'orientation: '. $im->getImageOrientation().'<br>'; // 6
echo '$srcImgWidth: '.$srcImgWidth.'<br>';
echo '$srcImgHeight: '.$srcImgHeight.'<br>';

The image size was 480x640

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • I believe the image orientation of 6 is `RightTop`, so the width/height (or columns/rows) should be adjusted accordingly. – emcconville Apr 25 '18 at 17:24
  • 1
    You have come across a problem where different software treats EXIF data differently. Some auto rotate the image others do not; I found this post on stackoverflow which may be of interest: https://stackoverflow.com/questions/4266656/how-to-stop-php-imagick-auto-rotating-images-based-on-exif-orientation-data?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Bonzo Apr 25 '18 at 17:50

0 Answers0