user3905568
user3905568

Reputation: 13

Images get rotated by 90 Whole resizing using gd2 in CodeIgniter

I had used gd2 library to resize image.But some images got rotated by 90 degree after resized but not all image.I hadn't used any rotation.What may be the reason behind this?Do I need to set anything other configuration?

My code is here :

if(isset($_FILES) && !empty($_FILES)){

    $item_images = $_FILES;
    $this->load->library('upload');
    $this->load->library('image_lib'); 
    $config['upload_path']   = './temp/';
    $config['allowed_types'] = '*';
    $this->upload->initialize($config);

    //print_r($item_images);
    foreach($item_images as $ind=>$img_name){
        if($this->upload->do_upload($ind)){

            $data_image                     = $this->upload->data();


            //for cropping
            $config_crop['image_library'] = 'gd2';
            $config_crop['source_image']     = $config['upload_path'] . $data_image['file_name'];
            $config_crop['create_thumb']     = FALSE;
            $config_crop['maintain_ratio']   = TRUE;
            $config_crop['width']       = 300;
            $config_crop['height']      = 300;
            //$config_crop['rotation_angle'] = '0';
            //$config_crop['x_axis'] = '100';
            //$config_crop['y_axis'] = '40';

            $this->image_lib->initialize($config_crop);


            if ( ! $this->image_lib->resize())
            {
                echo $this->image_lib->display_errors(); 
            }

        }
        $image_thumb = $this->s3_model->upload_image('thumb_'.$img_name['name'] ,$config['upload_path'] . $data_image['file_name']);
        if($image_thumb){
            $result = $this->s3_model->upload_image($img_name['name'] ,$img_name['tmp_name']);
            //unlink($config['upload_path'] . $data_image['file_name']);
        }


        if(! $result){
            $flag = false; //Error in uploading image.
            break;
        }
    }


} 

Upvotes: 1

Views: 1772

Answers (1)

Gestudio Cloud
Gestudio Cloud

Reputation: 290

Do you have a OSx working machine?

In my case, a pic, that in my Mac was shown correctly, indeed was turned sideways, that is because OSX preview detects CellPhone orientation while the pic was taken....

The server not, neither windows machines... so that was driving me crazy...

Being or not this your case, you can use exif_read_data() function. This will give you orientation data if it exists on photo's metadata.

Check here: How to detect shot angle of photo, and auto rotate for website display like desktop apps do on viewing?

Upvotes: 1

Related Questions