Crop Images Guide

Develop your own solution to crop JPG, PNG and GIF by integrating with the iLoveIMG REST API.

New to the API? Start with Processing an image: every tool guide builds on its task flow.

Basic crop

To crop an image you need to set the properties width and height to create a crop area. Also, x and y set the crop area origin, in pixels from the left and top edges of the image.

Start taskPHP
// Create a new task
$myTask = $iloveimg->newTask('crop');
// Add files to task for upload
$file = $myTask->addFile('path/to/file_name.jpg');

// crop an area of 25x50px starting 10px from the top and 10px from the left

// Set your crop origin coordinates
$myTask->setX(10);
$myTask->setY(10);

// Set the size to crop
$myTask->setWidth(25);
$myTask->setHeight(50);

// Execute the task
$myTask->execute();

// Download the cropped file
$myTask->download();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php