Welcome Guest, Not a member yet? Register   Sign In
How does the crop function works ? I followed the user_guide but can't make it work !
#1

[eluser]DocFunky![/eluser]
Hi there,

I can't crop my image automatically, let say I just want a 360 large part of the center of my image, so I did something like that : EDIT: I just put an harcoded x&y_axis to make the exemple simplier ..

Code:
$config['image_library'] = 'GD2';
      $config['source_image'] = $path;
      $config['maintain_ratio'] = TRUE;
      $config['width']  = '250';
      $config['height'] = '360';//Paramètres
      $config['x_axis'] = '200';
      $config['y_axis'] = '200';//normalement pas besoin de rogner ici

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

      if ( ! $this->image_lib->crop())
      {
       echo $this->image_lib->display_errors();
      }
      
     print "<img src='".base_url($path)."'  class='preview'>";
     }

Tight after my resize, but the function return the original image, without doing anything, no error message neither. Does anyone know why ?
Thanks Smile
#2

[eluser]superfake123[/eluser]
You will need to set the x-axis (left), width (right), y-axis (top), and height (bottom). You need to be sure to set the width and height of the image.

Code:
list($width, $height, $type, $attr) = getimagesize($img);
$CI->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $img;
$config['x_axis'] = '10';
$config['y_axis'] = '10';
$config['maintain_ratio'] = FALSE;
$config['width'] = $width-10;
$config['height'] = $height-10;

The code above will crop the image by 10 pixels on the left, right, top, and bottom. you can feel free to change the value of '10' to whichever value you prefer Wink
#3

[eluser]DocFunky![/eluser]
O-M-G
You saved my life, you can't even realize how ! the project was for tomorrow !
The only difference here is the True => FALSE Maintain ratio, that's why ..

Thanks you Smile




Theme © iAndrew 2016 - Forum software by © MyBB