CodeIgniter Forums

Full Version: how to crop?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]aryan_[/eluser]
how to re-size and crop an existing image in 125x125 dimension from center?

El Forum

[eluser]Krzemo[/eluser]
That should work

Code:
$cconfig['image_library'] = 'gd2';
$cconfig['source_image'] = $source_image_file_path;
$cconfig['maintain_ratio'] = FALSE;
$cconfig['width'] = 125;
$cconfig['height'] = 125;
$cconfig['new_image'] = $new_image_full_path;

//use ie getimagesize($source_image_file_path) to get orig img dims
$cconfig['x_axis'] = round(($orig_img_width - 125) / 2, 0);
$cconfig['y_axis'] = round(($orig_img_height - 125) / 2, 0);
            
$this->image_lib->initialize($cconfig);
$this->image_lib->crop();

Regs
K.

El Forum

[eluser]aryan_[/eluser]
How can I get width and height of an image? My images are of different sizes.

El Forum

[eluser]Krzemo[/eluser]
its all in my post above

El Forum

[eluser]aryan_[/eluser]
[quote author="Cshamoh" date="1275406591"]its all in my post above[/quote]

I mean $orig_img_width. Am I unable to find it in your code?

El Forum

[eluser]Krzemo[/eluser]
see the comment right above Smile

El Forum

[eluser]aryan_[/eluser]
[quote author="Cshamoh" date="1275437880"]see the comment right above Smile[/quote]
Oh! My mistake. Thanks a lot.

El Forum

[eluser]Krzemo[/eluser]
Just a thought...
If your original images are of different sizes it might be worth to crop maximum possible square and then resize it to 125x125. Thumbs will be more informative.
Let say you take original image, check what is smaller - width or height, crop a square with sides of that value and then resize it.

Have fun