Last active
August 29, 2015 14:20
-
-
Save komackaj/6ece1700a05c363771a4 to your computer and use it in GitHub Desktop.
Apply palette
This file contains 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
import pgmagick | |
if __name__ == "__main__": | |
# load input image and palette | |
img = pgmagick.Image('origRGBA.png') | |
palette = pgmagick.Image('palette.png') | |
# make input image binary opaque - needed for PNG8 | |
img.channelDepth(pgmagick.ChannelType.MatteChannel, 1) | |
# apply palette | |
img.map(palette, False) | |
# set background to rgb(0,0,0,0) - input image background color is | |
# set to white, would fail with error from Magick: | |
# "Invalid background palette index" | |
img.backgroundColor('none') | |
# save it as sRGB PNG - OK | |
img.write("palRGBA.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment