Skip to content

Instantly share code, notes, and snippets.

@bobmagicii
Created July 6, 2012 17:51
Show Gist options
  • Save bobmagicii/3061604 to your computer and use it in GitHub Desktop.
Save bobmagicii/3061604 to your computer and use it in GitHub Desktop.
colorizing greyscale images whilst preserving alpha
<?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