File indexing completed on 2025-01-05 04:00:26

0001 #!/usr/bin/env python3
0002 
0003 import sys
0004 import os
0005 import argparse
0006 sys.path.insert(0, os.path.join(
0007     os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
0008     "lib"
0009 ))
0010 from lottie import __version__
0011 
0012 parser = argparse.ArgumentParser(
0013     description="Shows the palette of a raster image"
0014 )
0015 parser.add_argument("--version", "-v", action="version", version="%(prog)s - python-lottie " + __version__)
0016 parser.add_argument(
0017     "infile",
0018     help="Input file"
0019 )
0020 parser.add_argument(
0021     "--colors", "-c",
0022     default=1,
0023     type=int,
0024     help="Number of colors to quantize"
0025 )
0026 
0027 if __name__ == "__main__":
0028     from lottie.parsers.raster import RasterImage
0029     ns = parser.parse_args()
0030 
0031     raster = RasterImage.open(ns.infile)
0032     palette = raster.k_means(ns.colors)
0033 
0034     for color in palette:
0035         print("#%02x%02x%02x %f : %s" % (
0036             int(round(color[0])),
0037             int(round(color[1])),
0038             int(round(color[2])),
0039             color[3] / 255,
0040             list(color/255),
0041         ))