CodeIgniter Forums
CI's image_lib cropping isn't working properly - 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: CI's image_lib cropping isn't working properly (/showthread.php?tid=15632)



CI's image_lib cropping isn't working properly - El Forum - 02-10-2009

[eluser]KeyStroke[/eluser]
Hi,

I'm using a javascript interface to pass the X/Y axis and height/width to CodeIgniter to crop images. I noticed that cropping, for some reason, isn't working properly. It doesn't crop exactly where I want, and it seems to ignore the width I provide.

Note that the following CI code doesn't work:
Code:
$this->load->library('image_lib');

$image_uri = './resources/images/picture.jpg';


$config['x_aixs'] = $this->input->post('x');
$config['y_axis'] = $this->input->post('y');
$config['source_image'] = $image_uri;
$config['width'] = $this->input->post('w');
$config['height'] = $this->input->post('h');
$config['maintain_ratio'] = TRUE;

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

if( ! $this->image_lib->crop() )
{
    echo $this->image_lib->display_errors();
}

Whereas this native PHP code that I've copied from the javascript cropping library works perfectly fine:
Code:
$targ_w = $targ_h = 150;
$jpeg_quality = 90;

$src = './resources/images/picture.jpg';
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);

header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);*/


Any idea what's wrong?

Your help is much appreciated Smile


CI's image_lib cropping isn't working properly - El Forum - 02-10-2009

[eluser]helmutbjorg[/eluser]
No idea as to your problem. I've hit on many drawbacks using the native image library. I use class.upload.php from verot.net... It is very good.


CI's image_lib cropping isn't working properly - El Forum - 02-11-2009

[eluser]TheFuzzy0ne[/eluser]
I don't see where you are passing your $config array to the image library.


CI's image_lib cropping isn't working properly - El Forum - 02-11-2009

[eluser]KeyStroke[/eluser]
Oh crap, lol. I forgot to include that too. Here's the whole function:

Code:
function crop_image()
{
$this->load->library('image_lib');

$image_uri = './resources/images/picture.jpg';

$config['x_aixs'] = $this->input->post('x');
$config['y_axis'] = $this->input->post('y');
$config['source_image'] = $image_uri;
$config['width'] = $this->input->post('w');
$config['height'] = $this->input->post('h');
$config['maintain_ratio'] = TRUE;

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

if( ! $this->image_lib->crop() )
{
    echo $this->image_lib->display_errors();
}

}



CI's image_lib cropping isn't working properly - El Forum - 02-11-2009

[eluser]TheFuzzy0ne[/eluser]
Code:
$config['x_aixs'] = $this->input->post('x');

should read:

Code:
$config['x_axis'] = $this->input->post('x');

axis is spelt incorrectly. Smile

Don't you just hate typoos? Tongue


CI's image_lib cropping isn't working properly - El Forum - 02-11-2009

[eluser]KeyStroke[/eluser]
Noooooooooooooo. I can't believe I've overlooked such thing. :'(

I guess it happens when do you too much work.

Thanks a lot TheFuzzy0ne. Smile


CI's image_lib cropping isn't working properly - El Forum - 02-11-2009

[eluser]TheFuzzy0ne[/eluser]
[quote author="KeyStroke" date="1234370572"]
I guess it happens when do you too much work.
[/quote]

Incorrect. It's usually a result of having too much blood in the caffeine stream. More coffee ought to fix it!