One of the newest additions to my project portfolio site (serverlessfoo.com) is the Chameleon color scheme API. The API returns a random color scheme of dominant and auxiliary colors in rgb form to be applied to a website. Here’s how I built the API for less than a penny.
This project had a few initial steps:
- Gather copyright-free images from pexels.com.
- Process all these landscape images and generated a color scheme using the Python ColorThief library. This returns results in the format
rgb(#, #, #)
. - Take the resulting dominant color and palette values and structure them uniformly into JSON.
- Load the JSON into an AWS DynamoDB table.
- Develop the API itself using the Serverless Framework.
- Test, test, test.
- Deploy the v1 api to AWS and create a microsite on serverlessfoo.com to demonstrate the functionality.
All of these setup steps are free to run locally and AWS services cost a fraction of a cent to keep this API running. This does assume I don’t start getting a massive influx of traffic, but I can add rate-limiting if I ever reach that point to cap my costs.
This is one of the newest micro-APIs I’ve been working on. I hope to extend the functionality of the current demo to allow the user to upload an image in the browser, have that image processed, and return a color scheme for that image dynamically. This presents a few new challenges for handling binary data with the AWS API Gateway so I’ve decided to release the first version now and iterate on it when I have a free weekend.
In case you’re wondering, the initial inspiration for this project came from design seeds. After unsuccessfully convincing them to partner with me to create this using their data and imagery I decided to just make one on my own.
If you’d like, you can check out the project code on GitHub and use that to deploy your own version.