Reputation: 10849
So I’m cropping an image I’m uploading with the following code (successfully):
$file_name = $this->input->post('file_name');
$x1 = $this->input->post('x1');
$y1 = $this->input->post('y1');
$x2 = $this->input->post('x2');
$y2 = $this->input->post('y2');
//die('width: '.$width.' height: '.$height.' id: '.$id.' file_name: '.$file_name.' x1: '.$x1.' x2: '.$x2.' y1: '.$y1.' y2: '.$y2.' w: '.$w.' h: '.$h);
$config['image_library'] = 'gd2';
$config['source_image'] = './images/uploads/temp/'.$file_name;
$config['maintain_ratio'] = FALSE;
$config['width'] = $y2;
$config['height'] = $y2;
$config['x_axis'] = $x1;
$config['y_axis'] = $y1;
$this->image_lib->initialize($config);
And at this point I want to resize the image as I have just gotten the selection and ratio I want and am not sure how to do this. Here’s what I assumed would work immediately afterward in the same method:
$config['width'] = 180;
$config['height'] = 180;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
if ( ! $this->image_lib->resize() )
{
die( $this->image_lib->display_errors() ); //
}
It doesn’t give any errors or anything, it just doesn’t resize the image. Can you please help me figure out what's going on?
Upvotes: 1
Views: 720
Reputation: 25435
It's as if the second time you load the library (thus initializing it again) it doesn't receive all the params it needs. Are you using the code in the same method, or in another? Anyway, if inside the same method, as a test try doubling some configs after clearing them:
//
//CROPPING HERE....Then:
//
$this->image_lib->clear();
$config['image_library'] = 'gd2';
$config['source_image'] = './images/uploads/temp/'.$file_name;
$config['maintain_ratio'] = TRUE;
$config['width'] = 180;
$config['height'] = 180;
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
And be sure to have the folder and files with correct permissions.
Upvotes: 2