How to Stop PHP Imagick Auto-Rotating Images Based on Exif 'Orientation' Data

How to stop PHP iMagick auto-rotating images based on EXIF 'orientation' data

Try Imagick::setImageOrientation. Experiment with the available constants.

Detect EXIF Orientation and Rotate Image using ImageMagick

Use the auto-orient option of ImageMagick's convert to do this.

convert your-image.jpg -auto-orient output.jpg

Or use mogrifyto do it in place

mogrify -auto-orient your-image.jpg

PHP read_exif_data and Adjust Orientation

The documentation for imagerotate refers to a different type for the first parameter than you use:

An image resource, returned by one of the image creation functions,
such as imagecreatetruecolor().

Here is a small example for using this function:

function resample($jpgFile, $thumbFile, $width, $orientation) {
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($jpgFile);
$height = (int) (($width / $width_orig) * $height_orig);
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpgFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Fix Orientation
switch($orientation) {
case 3:
$image_p = imagerotate($image_p, 180, 0);
break;
case 6:
$image_p = imagerotate($image_p, 90, 0);
break;
case 8:
$image_p = imagerotate($image_p, -90, 0);
break;
}
// Output
imagejpeg($image_p, $thumbFile, 90);
}

img unwanted photo rotation

Run jhead -autorot on your JPG image. That's what I do to handle autorotation before putting my images on the web.

This will rotate the image as specified by the camera's orientation sensor, then reset the orientation flag so that it will not be accidentally rotated again.

http://www.sentex.net/~mwandel/jhead/usage.html

(Note, I never autorotate my originals, just the scaled versions as part of my script for sending them to the web.)



Related Topics



Leave a reply



Submit