CodeIgniter Forums
Croping problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Croping problem (/showthread.php?tid=59542)



Croping problem - El Forum - 10-18-2013

[eluser]lucky8919[/eluser]
Hi there,

I'm having a problem when I've to resize and crop an image. For some reason after the cropping process is finish it's leaving a grey space between the image and the space that was cropped.

This is my code:

Code:
$w_orig = $file_data['image_width'];
  $h_orig = $file_data['image_height'];
  
  if ( $w_orig > $this->config['width'] )
  {
   $w_med = $this->config['width'];
   $h_med = ( $h_orig * $this->config['width'] ) / $w_orig;
  }
  else
  {
   $w_med  = $w_orig;
   $h_med  = $h_orig;
  }
  
  // global config
  $config['image_library']  = 'gd2';
  $config['source_image']  = $file_data['full_path'];
  $config['create_thumb']  = FALSE;
  $config['maintain_ratio']  = FALSE;
  $config['width']         = $w_med;
  $config['height']        = $h_med;
  
  $this->CI->image_lib->initialize ( $config );
  $this->CI->image_lib->resize();
  
  $imageSize = $this->CI->image_lib->get_image_properties($config['source_image'], TRUE);
  
    // axis settings
  $config['image_library']  = 'gd';
  $config['source_image']  = $file_data['full_path'];
  $config['create_thumb']  = FALSE;
  $config['maintain_ratio']  = FALSE;
  $config['x_axis']         = 0;
  $config['y_axis']        = ( ( $imageSize['height'] / 2 ) - ( $this->config['height'] / 2 ) );
  
  $this->CI->image_lib->initialize ( $config );
  $this->CI->image_lib->crop();
  $this->CI->image_lib->clear();

I'm leaving an image so you can see more clearly what my problem is.

I hope you can help me.

Thanks!


Croping problem - El Forum - 10-19-2013

[eluser]lucky8919[/eluser]
Please, anyone can help me with this?


Croping problem - El Forum - 10-20-2013

[eluser]lucky8919[/eluser]
This solve my problem. I hope it can helps.

http://kennykee.com/138/codeigniter-resize-and-crop-image-to-fit-container-div-example/