https://github.com/emnasc/solid-color-api
Simple API to generate solid color images
https://github.com/emnasc/solid-color-api
api api-rest flask images python
Last synced: 2 months ago
JSON representation
Simple API to generate solid color images
- Host: GitHub
- URL: https://github.com/emnasc/solid-color-api
- Owner: emnasc
- Created: 2020-07-04T17:03:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-12T20:15:39.000Z (almost 6 years ago)
- Last Synced: 2025-03-16T11:30:35.973Z (over 1 year ago)
- Topics: api, api-rest, flask, images, python
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Solid Color API
This project is a simple Flask API to generate solid color images based on given parameters
## Project environemnt and setup
This project is built on top a Pipenv virtual environment, based on a Python 3.6.0 interpreter. The environment can be setup using the following commands:
``` shell script
pip install pipenv #in case you already have pipenv installed, this line can be skipped
pipenv shell
```
This project uses [Flask](https://flask.palletsprojects.com/en/1.1.x/) and [Python Imaging Library (PIL)](http://www.pythonware.com/products/pil/) as it's dependencies, asside from `BytesIO` and `re` from Python's standard library.
## Running the project
This project can be run as a simple Python script, as follows:
```shell script
python app.py
```
## Calling the API
The API accepts GET requests, requiring three parameters decribing the image to be generated:
+ the image's width, as `width`
+ the image's height, as `height`
+ an hexadecimal code of either length 3 or 6 corresponding to the desired color, as `hex-color`
If any of those parameters is not provided, the API will return a `400` error with a message indicating the missing parameter
```shell script
curl --location --request GET 'http://127.0.0.1:5000/?width=400hex-color=5F4B8B'
```
> Height not provided
Otherwise, the script will return a solid color JPEG image corresponding to the given parameters
```shell script
curl --location --request GET 'http://127.0.0.1:5000/?width=150&height=200&hex-color=888'
```
> 
Otherwise, the API will returns a `500` status code with either a appropriate custom message or an error description
```shell script
curl --location --request GET 'http://127.0.0.1:5000/?width=150&height=200&hex-color=potato'
```
> Error: Invalid hex code: potato