palette-server is a small little WSGI-compliant httpony to extract colours from an image.
palette-server is a small Flask based HTTP-pony to extract colours from an image.
This package is officially DEPRECATED. You should consult plumbing-palette-server instead.
$> curl 'http://localhost:5000/extract?path=cat.jpg' | python -m json.tool
{
"reference-closest": "css3",
"average": {
"closest": "#808080",
"colour": "#8e895a",
},
"palette": [
{
"closest": "#a0522d",
"colour": "#957d34",
},
{
"closest": "#556b2f",
"colour": "#786438",
},
{
"closest": "#bdb76b",
"colour": "#b0a370",
},
{
"closest": "#556b2f",
"colour": "#576710",
},
{
"closest": "#808080",
"colour": "#827968",
}
],
"stat": "ok"
}
Did you notice the way the path for the request is /extract
? There are two reasons for that:
palette-server
Currently there is only one colour analysis tool – Giv Parvaneh’s RoyGBiv – but there may be others some day. You can address it directly like this:
$> curl 'http://localhost:5000/extract/roygbiv/?path=cat.jpg'
palette-server
also allows you to pair the colour palette to any reference grid that the cooperhewitt-swatchbook library exports. For example, if you want to use the Crayola crayon colour scheme as a reference you could say:
$> curl 'http://localhost:5000/extract/roygbiv/crayola?path=cat.jpg'
The default reference grid is CSS3.
If you just want to test that the server is up and running you can call the /ping
endpoint, like this:
$> curl 'http://localhost:5000/ping'
{
"stat": "ok"
}
palette-server
limits itself to processing only those images that it can find in a user-defined directory. Currently this is being configued as an environment variable (mostly because none of the configuration options for Flask stand out as “simple”). For example:
$> EXPORT PALETTE_SERVER_IMAGE_ROOT=/path/to/images
Alternative suggestions and patches are welcome. This works but is not awesome, by any means.
There is none, by default. This is not necessarily a service that is meant to be public-facing and assumes that unless you are planning to open things up to the world that you are running on a machine with suitable access control restrictions at the network layer.
palette-server
is a Flask application so you can start it up, from the command-line, like this:
$> cd palette-server
$> EXPORT PALETTE_SERVER_IMAGE_ROOT=/path/to/images
$> python flask/server.py
INFO:werkzeug: * Running on http://127.0.0.1:5000/
INFO:werkzeug: * Restarting with reloader
palette-server
will work with any WSGI-compliant server architecture but there are sample configuration files and init.d
scripts included with this repository for running things, as a daemonized service, under gunicorn.
POST
support (upload files)