Laravel Image Intervention avoid rotation

Viewed 4156

I'm uploading an iPhone image - taken by iPhone camera in vertical - with the dimensions of 2448x3264 and because this dimensions are so high (?) when I create a thumb of 600x360 it automatically rotates to horizontal.

What have I tried without any success:

  • Change the thumb dimensions
  • Use the fit function
  • Use the resize function
  • Use the crop function
  • Use the upsize and aspectRatio methods
  • Set only the height and use null on width
  • Set only the width and use null on height

The thumb must have a maximum of height of 360 and I'm ok if the width is not 600.

$imageResize = Image::make($originalFile);
$imageResize->fit(600, 360, function ($constraint)
{
    $constraint->upsize();
});
$imageResize->save($thumbPath);

My goal is to have:

  • Thumbnails in vertical if the original photo is vertical
  • Thumbnails in horizontal if the original photo is horizontal

How can I achieve this?

3 Answers

As spoke before, the image is being saved in its correct orientation and at the point of resizing you are running the fit() function on which I was able to find some information on this issue running along side that which suggests you need to use orientate() with fit.

An example here:

$imageResize = Image::make($originalFile);
$imageResize->orientate()
->fit(600, 360, function ($constraint) {
    $constraint->upsize();
})
->save($thumbPath);

I'm glad this helped.

According to this github issue you may need to run orientate() before fit():

$imageResize = Image::make($originalFile)
    ->orientate()
    ->fit(600, 360, function ($constraint) {
        $constraint->upsize();
    })
    ->save($thumbPath);
$img = Image::make($originalFile);

$img->orientate();
$img->resize(1024, null, function($constraint){
    $constraint->upsize();
    $constraint->aspectRatio();
});
$img->save();
Related