Welcome Guest, Not a member yet? Register   Sign In
Codeigniter image rotate when image resize
#2

 I fixed it with exif_read_data() . Here is my code:


Code:
$config['upload_path'] = './uploads/';
   $config['allowed_types'] = 'jpg|jpeg|gif|png';
   $config['max_size'] = '6048';
   $this->load->library('upload', $config);

   //check if a file is being uploaded
   if(strlen($_FILES["testimg"]["name"])>0){

       if ( !$this->upload->do_upload("testimg"))//Check if upload is unsuccessful
       {
           $error = array('error' => $this->upload->display_errors());
           print_r($errors);
       }
       else
       {

           $config['image_library'] = 'gd2';
           $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
           $filename = $_FILES['testimg']['tmp_name'];


           $imgdata=exif_read_data($this->upload->upload_path.$this->upload->file_name, 'IFD0');


           list($width, $height) = getimagesize($filename);
           if ($width >= $height){
               $config['width'] = 800;
           }
           else{
               $config['height'] = 800;
           }
           $config['master_dim'] = 'auto';


           $this->load->library('image_lib',$config);

           if (!$this->image_lib->resize()){  
               echo "error";
           }else{

               $this->image_lib->clear();
               $config=array();

               $config['image_library'] = 'gd2';
               $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;


               switch($imgdata['Orientation']) {
                   case 3:
                       $config['rotation_angle']='180';
                       break;
                   case 6:
                       $config['rotation_angle']='270';
                       break;
                   case 8:
                       $config['rotation_angle']='90';
                       break;
               }

               $this->image_lib->initialize($config);
               $this->image_lib->rotate();

           }
      }      
  }  



Here is the exif orientation chart



Code:
1        2       3      4         5            6           7          8

888888  888888      88  88      8888888888  88                  88  8888888888
88          88      88  88      88  88      88  88          88  88      88  88
8888      8888    8888  8888    88          8888888888  8888888888          88
88          88      88  88
88          88  888888  888888
Reply


Messages In This Thread
RE: Codeigniter image rotate when image resize - by ashisbiswas - 04-15-2016, 10:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB