Image Processing API written in Python, using the Pillow library for increasing the brightness of an image and exposing the functions with the Flask framework. The API is tested with png and jpg format.
There are three Python files:
app.py- includes the basic calls of the API. Run the file and use theGETandPOSTrequests onlocalhost:5000.image_processing.py- includes the function that takes of care of brightening the image.client.py- a client script to send an image to test thePOSTrequests and obtain a response, decode and save the image locally.app.pyneeds to be running.
Other files included are input_image.png is the image sent by the client script for testing and modified_image.jpg is the resultant image after brightening.
Python installation requires the PIL (Pillow) library for image processing, flask and requests library. It is recommended to use the requirements.txt file
pip install -r requirements.txt
No additional configuration is needed to run the API in its basic form. However, you can configure the Flask application settings by modifying the app.run(debug=True) line in the app.py file.
Start the Flask application by running:
python app.py
This will start the server on http://127.0.0.1:5000/ with the GET request as default with 'Image Processing API' being displayed on the server. Below is the screenshot of the same:
- Method - POST
- Content-type - application-type
With app.py still running, run the command:
python client.py
This will send the input_image as request to the API and provide the modified_image saved locally on your machine.
To change the input image, replace input_image.png in the function call process_image('input_image.png') and to save in your own location replace modified_image.jpg in the line with open('modified_image.jpg', 'wb') as f in the file client.py.
The API provides basic error handling, returning a 400 status code if the image data is not found in the request and a 500 status code for any other errors that occur during processing.
The increase in brightness was adjusted by a factor of 30%. The images are shown below for comparison:
On the left is the input image and the right is the modified image. It is observed that there is a slight increase in brightness, since the brightness factor is not much the increase seems minimal. When increasing the brightness factor in the file image_processing.py, the modification produces a brighter image.

