I wrote a script to batch resize uploaded images locally and create thumbnails. The problem is if some images are oriented vertically but after resizing they rotate horizontally.
This is caused by the exif orientation of the image. Is there an easy way to remove orientation exif from an image via PHP? I know Imagick can do it, but I can't/don't want to install it.
Is there any solution without it?
Now I'm solving this problem by opening such an image in an image editor and resaving it without retaining the exif information. Afterwards, when I resize such image in the script, the result is correct.
So I just want to remove exif from the image in PHP script before resizing.
I tried a function that checks the direction exif:
function removeExif($filename) { if (function_exists('exif_read_data')) { $exif = exif_read_data($filename); if($exif && isset($exif['Orientation'])) { $orientation = $exif['Orientation']; if($orientation != 1){ // $img = new Imagick($filename); // $img->stripImage(); // $img->writeImage($filename); } } } }
So I just need to replace the Imagick part with something else without installing any additional libraries, maybe using the already included GD or something.
Okay, so I decided to rotate the image instead of removing the exif, and it ended up having the same effect. So I check what the exif orientation value is (if any) and then based on that value I just use imagerotate and then resize the image. The result is perfect and no additional installation and libraries are required.