Welcome Guest, Not a member yet? Register   Sign In
image manipulation problem
#1

[eluser]kbauman[/eluser]
I currently upgraded to 1.7.2 and now when I use the image manipulation class I end up with duplicated file extensions. For instance, after uploading, I resize and crop the image, and copy them to new directories. The original image is something like: image.jpg, and the final image is image.jpg.jpg. This was never an issue before the upgrade. Anyone have any ideas?
#2

[eluser]daparky[/eluser]
Post your code and we'll take a look.
#3

[eluser]kbauman[/eluser]
The upload works fine, and the correct image is inserted into the database, but when the image is resized or cropped, the file extension is added on again.

Code:
function modify_page(){

        $this->load->helper('file');
        $this->load->library('image_lib');
        $page = $this->uri->segment(3, 0);    
        $id = $this->input->post('id');
        $photo_id = $this->input->post('photo_id');
        $photo_title = $this->input->post('photo_title');
////if a new image has been uploaded
        if((isset($_FILES['image']['name'])) && ($_FILES['image']['name'] != ''))
        {
          $image = str_replace(" ", "_", $_FILES['image']['name']);
          $photo_id = $this->pages_model->insertPagePhoto($this->input->post('photo_title'), $image);
        
          $config['upload_path'] = './uploads/';
          $config['allowed_types'] = 'gif|jpg|png';
          $config['max_size']    = '0';
          $config['max_width']  = '1000';
          $config['max_height']  = '1000';
          $config['overwrite'] = 'FALSE';
          $config['remove_spaces'] = 'TRUE';
          $this->load->library('upload', $config);
          $this->upload->do_upload('image');

          if ( ! $this->upload->do_upload('image'))
          {
              $message['upload'] = $this->upload->display_errors();
          }    
          else
          {
              $message['upload'] = $this->upload->data();
          }

          $up_data  = $this->upload->data();
          $up_data['image_library'] = 'GD2';
          $up_data['source_image'] = $up_data['full_path'];
          $config2 = $up_data;
          $config3 = $config2;
          $config2['new_image'] = './images/pages/'.$up_data['file_name'];
          $config2['quality'] = '100%';
          $config2['maintain_ratio'] = TRUE;
          if( ( $up_data['image_width'] > 400 ) || ( $up_data['image_height'] > 400 ) ) {
              $config2['width'] = 400;
              $config2['height'] = 400;
          }
          $this->image_lib->initialize($config2);
          $this->image_lib->resize();

          if ( ! $this->image_lib->resize())
          {
              $message['resize'] = $this->image_lib->display_errors();
          }    
          else
          {
              $message['resize'] = $up_data['file_name'];
          }

          $config3['new_image'] = './images/pages/thumbs/'.$up_data['file_name'];
          $config3['quality'] = '100%';
          $config3['maintain_ratio'] = TRUE;
          $config3['width'] = 100;
          $config3['height'] = 100;
          $this->image_lib->initialize($config3);
          $this->image_lib->resize();

          if ( ! $this->image_lib->resize())
          {
              $message['thumb'] = $this->image_lib->display_errors();
          }    
          else
          {
               unlink($up_data['full_path']);
              $message['thumb'] = $up_data['file_name']." thumbnail";
          }
      }

      if($id == '')
      {
        $display_order = $this->pages_model->countPages();
        $display_order = $display_order + 1;
        $this->pages_model->createPage($display_order, $photo_id);
        $this->db->set('content', $this->input->post('info'));
        $this->db->insert('pages');
      }
      else
      {
          $this->pages_model->modifyPage($id, $photo_id);
        $this->pages_model->modifyPhotoTitle($photo_id, $photo_title);
      }

      redirect('admin/pages/'.$page);

    }
#4

[eluser]kbauman[/eluser]
Well, I found a few mistakes that apparently still worked in 1.7.1, but not in 1.7.2. I was running the upload, resize, and crop actions twice. Once removed, the images had the correct name, however now the resize does not work. No errors are returned. It simply stops at:
Code:
$this->image_lib->resize()
If I remove the code that specifies the size everything works, other than the obvious fact that the image never gets resized. Any help would be appreciated.
Code:
function modify_page(){

        $this->load->helper('file');
        $this->load->library('image_lib');
        $page = $this->uri->segment(3, 0);    
        $id = $this->input->post('id');
        $photo_id = $this->input->post('photo_id');
        $photo_title = $this->input->post('photo_title');
////if a new image has been uploaded
        if((isset($_FILES['image']['name'])) && ($_FILES['image']['name'] != ''))
        {
          $image = str_replace(" ", "_", $_FILES['image']['name']);
          $photo_id = $this->pages_model->insertPagePhoto($this->input->post('photo_title'), $image);
        
          $config['upload_path'] = './uploads/';
          $config['allowed_types'] = 'gif|jpg|png';
          $config['max_size']    = '0';
          $config['max_width']  = '1000';
          $config['max_height']  = '1000';
          $config['overwrite'] = 'FALSE';
          $config['remove_spaces'] = 'TRUE';
          $this->load->library('upload', $config);

          if ( ! $this->upload->do_upload('image'))
          {
              $message['upload'] = $this->upload->display_errors();
          }    
          else
          {
              $message['upload'] = $this->upload->data();
          }

          $up_data  = $this->upload->data();
          $up_data['image_library'] = 'GD2';
          $up_data['source_image'] = $up_data['full_path'];
          $config2 = $up_data;
          $config3 = $config2;
          $config2['new_image'] = './images/pages/'.$up_data['file_name'];
          $config2['quality'] = '100%';
          $config2['maintain_ratio'] = TRUE;
          if( ( $up_data['image_width'] > 400 ) || ( $up_data['image_height'] > 400 ) ) {
              $config2['width'] = 400;
              $config2['height'] = 400;
          }
          $this->image_lib->initialize($config2);

          if ( ! $this->image_lib->resize())
          {
              $message['resize'] = $this->image_lib->display_errors();
          }    
          else
          {
              $message['resize'] = $up_data['file_name'];
          }

          $config3['new_image'] = './images/pages/thumbs/'.$up_data['file_name'];
          $config3['quality'] = '100%';
          $config3['maintain_ratio'] = TRUE;
          $config3['width'] = 100;
          $config3['height'] = 100;
          $this->image_lib->initialize($config3);

          if ( ! $this->image_lib->resize())
          {
              $message['thumb'] = $this->image_lib->display_errors();
          }    
          else
          {
               unlink($up_data['full_path']);
              $message['thumb'] = $up_data['file_name']." thumbnail";
          }
      }

      if($id == '')
      {
        $display_order = $this->pages_model->countPages();
        $display_order = $display_order + 1;
        $this->pages_model->createPage($display_order, $photo_id);
        $this->db->set('content', $this->input->post('info'));
        $this->db->insert('pages');
      }
      else
      {
          $this->pages_model->modifyPage($id, $photo_id);
        $this->pages_model->modifyPhotoTitle($photo_id, $photo_title);
      }

      redirect('admin/pages/'.$page);

    }
#5

[eluser]kbauman[/eluser]
In case anyone else runs into this issue, I had to change this:
Code:
$config2['maintain_ratio'] = TRUE;
        
        if( ( $up_data['image_width'] > 400 ) || ( $up_data['image_height'] > 400 ) ) {
                $config2['height'] = 400;
                $config2['width'] = 400;
        }
To this:
Code:
$config2['maintain_ratio'] = TRUE;
        
        if( ( $up_data['image_width'] > 400 ) || ( $up_data['image_height'] > 400 ) ) {
            if( $up_data['image_width'] > $up_data['image_height'] ) {
                $ratio = ($up_data['image_width'] / $up_data['image_height']);
                $config2['height'] = 400;
                $config2['width'] = 400 * $ratio;
            } else {
                $ratio = ($up_data['image_height'] / $up_data['image_width']);
                $config2['width'] = 400;
                $config2['height'] = 400 * $ratio;
            }
        }

I could not just set maintain_ratio to true and specify the desired size. The resize would not occur, and no errors were presented.




Theme © iAndrew 2016 - Forum software by © MyBB