Reduce white borders on images with Image Magick

Today i had a very big problem as i had to crop an image to get all the white border out. I tried multiple solution using GD library from PHP but did not get it right.

The solution I found came from Image Magick software. I install the software on Ubuntu and used the following code to remove the white borders from images:

 $im = new Imagick("pathtooldimage");
$im->trimImage(0.1 * $im->getQuantum());
$im->borderImage("#ffffff", 20, 20);
$im->setImagePage(0, 0, 0, 0);
$im->writeImage("path to new image");

Leave a Reply

Your email address will not be published. Required fields are marked *