note 95547 deleted from imagick.examples-1 by danbrown
| From: | danbrown@php.net | Date: | Fri, 08 Jan 2010 14:35:45 +0000 |
| Subject: | note 95547 deleted from imagick.examples-1 by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164785@lists.php.net to get a copy of this message | ||
Note Submitter: sabo_ at mail dot ru
----
function ResizeImage($inputFile, $outputFile, $width = 100, $height = 100, $background =
'#ffffff')
{
$image = new Imagick($inputFile);
$image->adaptiveResizeImage($width, $height, true);
$image->setImageFormat('png');
$image->setImageBackgroundColor($background);
$iHeight = $height - $image->getImageHeight();
if($iHeight%2 && $height > 0)
$top = 0 - ($iHeight - 1) / 2;
else
$top = 0 - $iHeight / 2;
$iWidth = $width - $image->getImageWidth();
if($iWidth%2 && $width > 0)
$left = 0 - ($iWidth - 1) / 2;
else
$left = 0 - $iWidth / 2;
$image->extentImage($width, $height, $left, $top);
$image->writeImage($outputFile);
$image->clear();
$image->destroy();
}