michael1986's avatar

Intervention image orientation taken by iPhone

Hi all,

For my project I need to upload images using an iPhone. This will be done in portrait mode, using a vue component which actually shows the image in portrait mode. The component creates a base64 version of the image which will be posted. So far so good.

On the Laravel side, this is a part of the function so far:

// Strip the first part of the base64 value.
$image = explode('.', $data['image']);

// Decode base64 value
$image = base64_decode($image[1], true); 

// Make image with auto orientate
$image = Image::make($image)->orientate();     
          
// Resize image
$image->resize(800, null, function ($constraint) {
    $constraint->aspectRatio();                       
});                                    

// Stream image               
$image = $image->stream()->__toString();      

// Save to S3.
Storage::disk('s3')->put($filename, $image, 'public'); 

Now the image actually gets uploaded to S3, but still in landscape mode, while take in portrait mode.

PHP is build using --enable-exif, using version 7.1.14

Anybody got an idea what to do next?

0 likes
3 replies
tykus's avatar

I had a similar issue, and gave up trying to rely on EXIF; instead I just interrogated the image myself:

if ($image->width() > $image->height()) {
    $image->rotate(90);
}
michael1986's avatar

@tykus Thanks for your suggestion, I've used rotate(270), but it still feels like some kind of hack for this issue.

@jaec86 I'm using the same vue component. As said, the image is showing in portrait mode in the vue component, but is uploaded in landscape mode.

Please or to participate in this conversation.