Welcome Guest, Not a member yet? Register   Sign In
Crop function in "image lib" library is not working
#1

[eluser]Stephane02[/eluser]
Hi,

I have issues using the Image Lib library. As I've been successfully used it for the other functions (resize, watermarking,...) the cropping function does not work at all and it does not return any error. The crop() function actually returns TRUE as if everything went through but the target image does not change and the last successes I had with the code below gave a black and not cropped image. Maybe you can help especially if any of you ever make it work. I would be happy if you can show me your working "cropping" codes. I've been googled on the subject and it seems many people have the same issue with this Codeigniter class.

Here's the code I'm using right now, what could be wrong?

Code:
$shot_config['create_thumb'] = FALSE;
$shot_config['source_image'] = './images/shots/'.$data['shot_info']['username'].'/'.$data['shot_info']['shot'];
$shot_config['new_image'] = './images/shots/'.$data['shot_info']['username'].'/cropped_'.$data['shot_info']['shot'];
$shot_config['width'] = $this->input->post('crop_width');
$shot_config['height'] = $this->input->post('crop_height');
$shot_config['x_axis'] = $this->input->post('crop_x_offset');
$shot_config['y_axis'] = $this->input->post('crop_y_offset');

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

if($this->image_lib->crop())
{
   echo 'crop ok';
}
else
{
   echo $this->image_lib->display_errors();
}

Thank you for helping,

Stephane
#2

[eluser]Atharva[/eluser]
Code:
$this->load->library('image_lib', $shot_config);
$this->image_lib->initialize($shot_config);

you are initializing the library twice. You can comment
Code:
$this->image_lib->initialize($shot_config);

Also, are you sure the source image exists while cropping?
#3

[eluser]Stephane02[/eluser]
The image exists, otherwise it would show some error. I cleaned up my code and it's working fine now. Thank you for pointing to the double initialization. I fixed that too.




Theme © iAndrew 2016 - Forum software by © MyBB