📅  最后修改于: 2023-12-03 14:59:59.717000             🧑  作者: Mango
Colorgram.py is a Python module that allows you to extract colors from images in a simple way. It can extract all the colors in an image or a limited number of colors, sorted by frequency.
You can install colorgram.py using pip:
pip install colorgram.py
First, you need to import the module:
import colorgram
To extract the colors from an image, you just need to call the extract
method:
colors = colorgram.extract('image.jpg', 10)
In this example, it will extract the 10 most frequent colors in the image.jpg
file.
You can also get all the colors in the image by omitting the second argument:
colors = colorgram.extract('image.jpg')
The result is a list of Color
objects, which have rgb
and hsl
attributes. You can access them like this:
color = colors[0]
print(color.rgb) # (255, 255, 255)
print(color.hsl) # (0, 0, 100)
Colorgram.py currently only supports JPEG and PNG images.
Using Colorgram.py, you can easily extract the colors from images and use them in your projects. Its simple API makes it a great choice for beginners and experts alike.