Is it possible to get a set of dominant colors from an App Engine Image (stored as a blob)?
With PIL, I can do this:
import Image
im = Image.open('image.jpg')
out = im.convert('P', palette=Image.ADAPTIVE, colors=5)
In App Engine, I get hold of the image like so:
image = images.Image(blob_key=blob_key)
Is it possible to get a palette from here?
The GAE images.Image class doesn't appear to offer a similar/pallette-based functionality.
But PIL is one of the GAE Built-in Third-party Libraries which you can use instead. You'd need to:
request the library in your app.yaml
:
libraries:
- name: PIL
version: "1.1.7"
explicitly use the Image
class from PIL
(may need to import it as a different name if you're also importing/using the Image
class from GAE's images
, to avoid a naming conflict):
from PIL import Image
im = Image.open('image.jpg')
out = im.convert('P', palette=Image.ADAPTIVE, colors=5)