Search code examples
ioslaravelintervention

Web App Image Rotate Issue


Problem:

When uploading image taken from iPhone, it is displayed on the website rotated 90 degrees counter-clockwise. I've done research and understand certain meta data contained in the image file is causing this. Is there a good library to determine if this meta data is in the file and rotate it properly?

My app is build with Laravel and I was looking at Intervention Image to see if maybe that can solve this.

Thanks!

UPDATE:

Still not working. I've checked the php modules and exif and mbstring are enabled on the server.

Here's my code in my laravel controller. The image saves to the directory I specify, but just doesn't orientate properly. Image taken on mobile still shows as rotated on desktop. Thanks!

if (Input::hasFile('profile-image'))
        {
            $extension = Input::file('profile-image')->getClientOriginalExtension();
            $fileName = rand(11111,99999).'.'.$extension;

            $image = Image::make(Input::file('profile-image'))->orientate()->save('images/profiles/'.$fileName);

            Auth::user()->update([
                'image_path' => $fileName,
            ]);
        }

Solution

  • Yes, you'll want the orientate() function it provides.

    http://image.intervention.io/api/orientate

    Modern cameras add EXIF data to photos that includes the orientation (as well as details about flash, exposure, aperture, etc.). Intervention and other libraries (I've used jhead in the past for autorotation) can use this data.