This is a simple example to demonstrate how to easily trim the areas off the image and only display the parts where the object lies.
Imagick::trimImage takes one parameter which is "fuzz". Quoting ImageMagick manual: "By default target must match a particular pixel color exactly. However, in many cases two colors may differ by a small amount.
The source image is a simple png image with black circle on gray background:
The trimmed image:
<?php
/* Create the object and read the image in */
$im = new Imagick( "test.png" );
/* The background color. This is what we trim. */
$im->setImageBackgroundColor( new ImagickPixel( "rgb(213,213,213)" ) );
/* Trim the image. */
$im->trimImage( 0 );
/* Ouput the image */
header( "Content-Type: image/" . $im->getImageFormat() );
echo $im;
?>
|