I'm not sure why, but when I upload a certain portrait image, it gets rotated to a landscape image, which shouldn't happen. The original image is "480 × 640", and I'm using the code below to resize (if necessary) to a maximum of 1024 pixels.
\Image::make(Request::file('image'))->resize(1024, null, function($constraint){ $constraint->upsize(); $constraint->aspectRatio(); })->save("useruploads/".$image_name);
This is my test image if anyone would like to try it out.
What's extra weird, is that github is also rotating the image after uploading, here is the original one take with an iphone: http://cl.ly/image/0h2m0H1o0D0m
Have you tried to use orientate() to correct image orientation after uploading?
$img = \Image::make(Request::file('image'));
$img->orientate();
$img->resize(1024, null, function($constraint){
$constraint->upsize();
$constraint->aspectRatio();
});
$img->save("useruploads/".$image_name);
Damned, I just found out that it's due to EXIF data being applied to the images, first time I encountered that. Thanks @olivervogel and sorry for logging the issue probably to quickly.
Just had this issue (only on large images). Solution still works, thanks!
Not found for me, some idea?
$img = Image::make($file);
$img->orientate();
$img->resize($width, $height, function ($constraint) {
$constraint->upsize()
})
->encode();
Storage::put($path, (string) $img);
For those who do not help "orientate" method, you should pay attention to the next line from the documentation:
Image object must be instantiated from file path to read the EXIF data correctly.
I instantiated it from URL to the picture, so this did not work for me.
@ArtemProkopenko so how did you solve the problem?
@chimit, I now have to first download the file from URL to disk and only then instantiated it from file path.
Why just can't maintain the original aspect ratio? Hard to believe in 2020 we required to read the image exif data to maintain the orientation of an image. This hasn't been a problem since the internet exists...
$img->orientate(); didn't help
Storing the file, open it and process that image (as suggested above) didn't help.
Still wrong orientation...
//Store original file
Storage::disk('uploads')->put($hash_file_name, $file);
//Get the file from the disc to read the exif data to maintain orientation
$file = Storage::disk('uploads')->get($hash_file_name);
$img = Image::make($file);
$img->orientate();
$img->resize(null, 400, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
Storage::disk('uploads')->put($hash_file_name.'.medium', $img->stream()->__toString());
Every portrait goes landscape :/
Most helpful comment
Have you tried to use orientate() to correct image orientation after uploading?