iPhone images rotating

I have also experienced this behaviour in the past. I then created a function that “works around” this as on a very low level, specifically for my use case.

hook:

kirby()->hook(['panel.file.upload', 'panel.file.replace'/* , 'panel.file.update' Necessary? */], function($file) {
  fixIphoneOrientation($file);
});

function:

function fixIphoneOrientation($file) {
    // Check also: https://stackoverflow.com/questions/18312243/how-do-i-use-imagick-in-php-resize-crop
    if(array_key_exists("Orientation", $file->exif()->data())) {
        if ($file->exif()->data()["Orientation"] == 6) {
            $img = new Imagick($file->root());
            $imageprops = $img->getImageGeometry();
            $width = $imageprops['width'];
            $height = $imageprops['height'];

            $img->rotateimage("#000", 90);
            $img->stripImage();
            $img->resizeImage($height,$width, imagick::FILTER_LANCZOS, 0.9, true);
            $img->writeImage($file->root());

        }
    }
}

I hope this helps a bit :slight_smile:

1 Like