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 mogrify
to 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
Change Name of Laravel's Created_At and Updated_At
Removing Black Borders 4:3 on Youtube Thumbnails
PHP How to Create Multiple Sessions
How to Store JavaScript Variable Output into a PHP Variable
How to Setup a Cron Job in Magento Module
PHP Pdo Insert Batch Multiple Rows with Placeholders
Retrieving the Last Inserted Ids for Multiple Rows
How to Convert Array to a String Using Methods Other Than JSON
How to Setup Docker + PHPstorm + Xdebug on Ubuntu 16.04
How to Install an Older Version of PHPunit Through Pear
PHP Artisan Migrate Throwing [Pdo Exception] Could Not Find Driver - Using Laravel
Best Way to Internationalize Simple PHP Website
Php: Check Who Had Read Sent Email
PHP Soap Client for Uk Mail Webservice API
When and Why Should $_Request Be Used Instead of $_Get/$_Post/$_Cookie
Laravel and View Caching in Development -- Can't See Changes Right Away