CI_Image_lib::crop()

crop()

Returns: TRUE on success, FALSE on failure
Return type: bool

The cropping method works nearly identically to the resizing function except it requires that you set preferences for the X and Y axis (in pixels) specifying where to crop, like this:

$config['x_axis'] = 100;
$config['y_axis'] = 40;

All preferences listed in the Preferences table are available for this method except these: rotation_angle, create_thumb and new_image.

Here’s an example showing how you might crop an image:

$config['image_library'] = 'imagemagick';
$config['library_path'] = '/usr/X11R6/bin/';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['x_axis'] = 100;
$config['y_axis'] = 60;

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

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

Note

Without a visual interface it is difficult to crop images, so this method is not very useful unless you intend to build such an interface. That’s exactly what we did using for the photo gallery module in ExpressionEngine, the CMS we develop. We added a JavaScript UI that lets the cropping area be selected.

doc_CodeIgniter
2016-10-15 16:31:37
Comments
Leave a Comment

Please login to continue.