Skip to content

Instantly share code, notes, and snippets.

@komackaj
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komackaj/6ece1700a05c363771a4 to your computer and use it in GitHub Desktop.
Save komackaj/6ece1700a05c363771a4 to your computer and use it in GitHub Desktop.
Apply palette
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