note 113930 added to imagick.colorizeimage
| From: | olav at redwall dot ee | Date: | Wed, 18 Dec 2013 12:24:18 +0000 |
| Subject: | note 113930 added to imagick.colorizeimage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197972@lists.php.net to get a copy of this message | ||
To improve upon "php at lfbittencourt dot com"'s solution, this one blends the
composited color, and takes opacity into account as well.
<?php
class YourImagick extends Imagick
{
public function colorize($color, $alpha = 1, $composite_flag = Imagick::COMPOSITE_COLORIZE)
{
$draw = new ImagickDraw();
$draw->setFillColor($color);
$geometry = $this->getImageGeometry();
$width = $geometry['width'];
$height = $geometry['height'];
$draw->rectangle(0, 0, $width, $height);
$temporary = new Imagick();
$temporary->setBackgroundColor(new ImagickPixel('transparent'));
$temporary->newImage($width, $height, new ImagickPixel('transparent'));
$temporary->setImageFormat('png32');
$temporary->drawImage($draw);
$alphaChannel = $this->clone();
$alphaChannel->setImageAlphaChannel(Imagick::ALPHACHANNEL_EXTRACT);
$alphaChannel->negateImage(false, Imagick::CHANNEL_ALL);
$this->setImageClipMask($alphaChannel);
$clone = $this->clone();
$clone->compositeImage($temporary, $composite_flag, 0, 0);
$clone->setImageOpacity($alpha);
$this->compositeImage($clone, Imagick::COMPOSITE_DEFAULT, 0, 0);
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/imagick.colorizeimage.php
Edit -- https://master.php.net/note/edit/113930
Del: integrated -- https://master.php.net/note/delete/113930/integrated
Del: useless -- https://master.php.net/note/delete/113930/useless
Del: bad code -- https://master.php.net/note/delete/113930/bad+code
Del: spam -- https://master.php.net/note/delete/113930/spam
Del: non-english -- https://master.php.net/note/delete/113930/non-english
Del: in docs -- https://master.php.net/note/delete/113930/in+docs
Del: other reasons-- https://master.php.net/note/delete/113930
Reject -- https://master.php.net/note/reject/113930
Search -- https://master.php.net/manage/user-notes.php