iPhone images rotating

Hello all -

I’ve been doing some reading on the forums regarding the issue of iphone images not being automatically rotated when uploaded to the panel.

I’m currently having the issue with a client site (kirby v 2.5.8) and I want to get it sorted, but don’t want to have to get them to do all sorts of processes to the image first to remove exif data etc.

From what I can read this is a known issue that was meant to be fixed in a previous version but still continues for some reason, and the most common suggested fix is adding a webhook. Is that correct?

My questions is 2 parts:

  • Is there a way to add this webhook whenever a page is saved, rather than when sort order or status is changed?
  • Is there a walkthrough for noobs like myself?


1 Like

I’d suggest to use a panel.file.upload hook: https://getkirby.com/docs/developer-guide/advanced/hooks

Thanks - do you know of any tutorials/topics that I’m missing that could help a noob implement this?

Honestly, I don’t know, I could never reproduce that issue with any of my iPhones’ images. What do you want to do with the image once it is uploaded? Remove the EXIF data?

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.


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


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->resizeImage($height,$width, imagick::FILTER_LANCZOS, 0.9, true);


I hope this helps a bit :slight_smile:

1 Like

Maybe someone of the devs might have a look at this, as this behaviour is consistently wrong with some iphone images in my experience?

It would be awesome if this would be part of the core (might refactor my code to be less hacky though :wink: ), so we don’t have to work our way around this.

It’s absolutely possible that this is inconsistent iPhone behaviour (so they are the culprit), but it’s one of the most used camera’s nowadays which makes it difficult to sell to our customers… I know I didn’t get this sold, so I had to hackfix my way around it.

@bvdputte, I tested it and your solution worked great, but unfortunately Dylan’s server don’t have Imagick installed.

Since Kirby does include some image manipulation out-of-the-box, I had the idea of searching to see if it included an image rotation method that didn’t require Imagick. Turns out that Kirby Toolkit includes a library called SimpleImage that has an auto_orient method that does exactly what he needed, fix orientation based on EXIF data. That method was not exposed to Kirby, but was there all the time and can be easily used.

I wrapped it in a plugin: https://github.com/pedroborges/kirby-auto-orient-images


Thx @pedroborges, that’s why I suggested if this could be added into core instead of with separate plugin/hooks wizardry :wink:

PS: I always try to get hosting with imagick as it has much better performance (in my experience).

I totally agree this should be backed into core. Maybe it gets in on Kirby 3.

Thanks for the help everyone - glad to know there’s some kirby wizards out there who have my back. Love the Kirby community!

1 Like