Welcome Guest, Not a member yet? Register   Sign In
Resizing image with maintain_ratio causes unwanted rotation
#1

I'm using the image library to resize images, with maintain_ratio set to true. My problem is that, while this works with landscape images, portrait images are rotated 90 degrees. Here is the body of my resize function:

PHP Code:
$config = array(
 
'source_image'   => $path.$file_name,
 
'width'          => 300,
 
'height'         => 200,
 
'maintain_ratio' => TRUE
 
);
 
$this->load->library('image_lib',$config);
 
$this->image_lib->initialize($config);
 if (!
$this->image_lib->resize()) return $this->image_lib->display_errors(); 
 
$this->image_lib->clear(); 

So this scenario works fine: input is a landscape image, 1920 x 1200, and it gets resized to 300 x 188.

This is the problem scenario: input is a portrait image, 2700 x 3700, which gets resized to 267 x 200 (fine), but rotated left 90 degrees.

I've seen this Stackoverflow question, but none of its attempts to fix were relevant to my situation.

Has anyone else experienced this bug? Any thoughts welcome!
Reply
#2

More than likely, the rotation of the image is being set by the EXIF data. There are a few Stackoverflow questions related to correcting the orientation in PHP, but this one looked the most helpful in my quick look at a handful of them: http://stackoverflow.com/questions/36570...-like-desk
Reply
#3

I had the same problem and I've lost a lot of time trying to understand it, in the end the only solution I found is to use EXIF data...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB