Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Colorific on Windows in a Python script #28

Open
frakman1 opened this issue Feb 17, 2016 · 1 comment
Open

Colorific on Windows in a Python script #28

frakman1 opened this issue Feb 17, 2016 · 1 comment

Comments

@frakman1
Copy link

Hi there,

I am trying to use colorific in a python script running on Windows so I won't be running a binary from the command line or virtual environment as in your examples.

I was able to install it using python setup.py install

My question is how do I use it to operate on an image object such as one returned by:

image = ImageGrab.grab() # take a screenshot

I am running this in a loop and constantly calculate the primary colours of the resultant screenshot image. How do I use the colorific library with the image object in this way?

Note that I could save the images as files and then read them with the script but since it is a real-time application, that would introduce far too much latency.I was hoping for a colorific interface that allows an input that is an image object instead of a file-name.

Thanks!

@frakman1 frakman1 changed the title Colorific on Windows Colorific on Windows in a Python script Feb 17, 2016
@illagrenan
Copy link

@frakman1 Take a look how colorific binary handles color extraction https://github.com/99designs/colorific/blob/master/colorific/script.py#L83.

Here is simple example:

from PIL import Image
from colorific.palette import extract_colors, rgb_to_hex


def get_palette():
    filename = "image.jpg"
    image_pil = Image.open(filename)

    palette = extract_colors(image_pil)
    """:type : colorific.palette.Palette"""

    print("Colors: ", ', '.join(rgb_to_hex(c.value) for c in palette.colors))

    if palette.bgcolor:
        print("Background: ", rgb_to_hex(palette.bgcolor.value))

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants