Created
July 6, 2012 17:51
-
-
Save bobmagicii/3061604 to your computer and use it in GitHub Desktop.
colorizing greyscale images whilst preserving alpha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function colorize($img,$color) { | |
$fill = new Imagick; | |
$fill->newImage( | |
$img->getImageWidth(), | |
$img->getImageHeight(), | |
$color | |
); | |
$img->compositeImage( | |
$fill, | |
Imagick::COMPOSITE_MULTIPLY, | |
0,0, | |
(Imagick::CHANNEL_RED|Imagick::CHANNEL_GREEN|Imagick::CHANNEL_BLUE) | |
); | |
$fill->destroy(); | |
} | |
$img = new Imagick('chip.png'); | |
colorize($img,'#00ff00'); | |
$img->writeImage('chip2.png'); | |
$img->destroy(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment