• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem cropping image with image_lib library

I'm trying to crop a rectangular image (1000 x 400 px) so that I get rid of about a fith part of its width from both sides, while keeping all of its height. Thus getting a centered frame.

As far as I know, based in the sparse documentation of CI on this, I had to firstly get rid of the left edge:

$config['source_image'] = $src;
$config['x_axis'] = 200;
$config['y_axis'] = 0;

Then, flip horizontally and next remove the right portion by repeating the first process:

$config['source_image'] = $src;
$config['rotation_angle'] = 'hor';

// Code for cropping again...

And flip again to turn it back to the initial state:

// Code for flipping again...

I'm using every single operation in a function, so note that $config is not the same variable for each one, and every operation should be completely independent.

The resulting image is this:

The right side is actually cropped. However the left side, instead of being cropped, has been displaced to the right by a black background stripe. So, the resulting width is just the same as the original picture, with the difference that looks like it has been displaced to the right, moving the rightmost portion outside, and covering the left portion with black.

What am I missing?

I had done something like that as my custom library. I'm not quite sure what is wrong there (hadn't read throughly), but you could use only one crop to do the job with some crop setting like...

'x_axis'=>200, // Let say this is (image_width-new_width)/2 which is (1000-600)-2
'y_axis'=>0, // The same thing could be apply here, but to follow you code, 0
'width'=>600, // Width after cropping, in your case, 600
'maintain_ratio'=>FALSE // maybe not required, just something from my code

It was working on my case (which has more stuff about crop horizontally, vertically, etc.), so it should work on yours

If you want to check what is wrong whit your code, you could check step by step:
1. exit(); after the first cropping, and check if the image is cropped correctly.
2. If(1) is OK, then exit(); after the flipping, is it still ok?
3. If(2) is also ok, then crop the 2nd time, exit() then check the image.
The last flipping shoulding be the problem...

I have try your code on mine, and it seems ythe first cropping is not working. After adding width config, the cropping works.

$config['source_image'] = $src;
$config['x_axis'] = 200;
$config['y_axis'] = 0;
$config['width']=1440-200; // My picture is 1440

Thank you Aquary, I finally did it using "width" and "maintain_ratio", as you suggested.

This means the CI documentation is wrong in this line, since it says "width" is not available in the crop function:

Quote:All preferences listed in the table above are available for this function except these: rotation_angle, width, height, create_thumb, new_image.


Someone should correct it.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.