Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Crop
#1

[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?
#2

[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!
#3

[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/
#4

[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.
#5

[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
#6

[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.
#7

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

[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
#9

[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');
#10

[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 .




Theme © iAndrew 2016 - Forum software by © MyBB