CodeIgniter Forums

Full Version: Codeigniter Crop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]alexaaaaaaaaaa[/eluser]
Hi all i have this code but it's not working like i want and i know there's something easy to find and fix

here's my code
Code:
$x = '9';
   $y = '-229';
   $data = $this->upload->data();
   $this->load->library('image_lib');
   $config['image_library'] = 'gd2';
   $config['source_image'] = 'uploads/111/05/'.$data['file_name'];
   $config['new_image'] = 'uploads/111/05/rsz/'.$data['file_name'];
   $config['maintain_ratio'] =FALSE;
   $config['y_axis'] = $y;
                 $config['x_axis'] = '9';
   $config['height'] = '183'-$y;
   $config['width'] = '697';
   $this->image_lib->initialize($config);  
   $this->image_lib->resize();
   $this->image_lib->crop();
but it's not cropping right....can you help me?

El Forum

[eluser]InsiteFX[/eluser]
For an image to look correct you need to keep the image aspct ratio!

512x512 256x256 128x128 64x64 32x32 16x16 8x8 4x4 2x2

Code:
height = 183 / 2;
width  = 697 / 2;

If you change just one axis your image will never look correct!

El Forum

[eluser]alexaaaaaaaaaa[/eluser]
[quote author="InsiteFX" date="1336750744"]For an image to look correct you need to keep the image aspct ratio!

512x512 256x256 128x128 64x64 32x32 16x16 8x8 4x4 2x2

Code:
height = 183 / 2;
width  = 697 / 2;

If you change just one axis your image will never look correct!
[/quote]

ok so why we split the height and width on 2 ? i need to crop to a specific size i have the x and y coordonates and based on that i need to crop. If you want i can give you the exact site from where i took the ideea http://fbcover.3fusion.in/

El Forum

[eluser]InsiteFX[/eluser]
You only need to divide by 2 4 6 8 etc to maintain the image aspect ratio.

You can do it anyway you want really but you need to do both height and width.

El Forum

[eluser]Mat-Moo[/eluser]
Couple of things, #1 Don't quote your numbers, they are integers so treat them as such. #2 Your height is less than 0? 183-229? don't make sense? #3 Check out my image moo library might make a bit more sense and easier to ue

El Forum

[eluser]CroNiX[/eluser]
[quote author="Mat-Moo" date="1336762675"]Couple of things, #1 Don't quote your numbers, they are integers so treat them as such. #2 Your height is less than 0? 183-229? don't make sense? #3 Check out my image moo library might make a bit more sense and easier to ue[/quote]

it's 183 - (-229), which is a positive number (412). Not sure why he's writing it that way though.

El Forum

[eluser]Mat-Moo[/eluser]
Good spot, my bad, as you say still daft Smile

El Forum

[eluser]alexaaaaaaaaaa[/eluser]
Maybe i didn't explain myself well

I have this image ok like 1025x 400 that i upload after i upload i can move it around and then i have the x and y coords to crop, it doesn't have to be square crop it must be 697x183
and crop the image...
So first we resize the pic to 697x183 and then we crop where x = 9 and y = -255 now i use this code

Code:
$x = '9';
   $y = '-369';
   $data = $this->upload->data();
   $this->load->library('image_lib');
   $config['image_library'] = 'gd2';
   $config['source_image'] = 'uploads/111/05/'.$data['file_name'];
   $config['new_image'] = 'uploads/111/05/rsz/'.$data['file_name'];
   $config['maintain_ratio'] =FALSE;
  
   $config['height'] = '183';
   $config['width'] = '697';
   $config['y_axis'] = $y;
         $config['x_axis'] = 9;
   $this->image_lib->initialize($config);  
   $this->image_lib->resize();
   $this->image_lib->crop();
   $this->image_lib->clear();
ps. just to make sure we are on the same page here's a print screen


http://www.picz.ro/show-image.php?id=505...aa2bc1bdb1

El Forum

[eluser]Mat-Moo[/eluser]
If your only cropping, why are you calling resize?

Did you look at image_moo? 3 lines of code, but it auto crops it to the center for you, so might not be any good...
$this->image_moo
->load('DSC01707.JPG')
->resize_crop(697,183)
->save('thumb_ddd.jpg');

El Forum

[eluser]alexaaaaaaaaaa[/eluser]
but after cropping i need to resize it right?
I took a look after your code and i'll let you know .
Pages: 1 2