image-manipulation-api-digitalocean is a Flask-based web service designed to perform various image processing tasks. It provides endpoints for resizing, cropping, rotating, converting to grayscale, adjusting brightness and contrast, flipping, applying filters, converting formats, adding text, and listing available fonts. This API deploys to DigitalOcean within a Docker container.
- Python: The script runs in a Python3 environment.
- Flask: This is used for creating the web server and handling the REST API HTTP requests.
- Flask-CORS: Handles Cross-Origin Resource Sharing (CORS).
- gunicorn: An extension that provides a Python WSGI HTTP Server for UNIX.
- NumPy: Used for handling numerical data, particularly arrays.
- OpenCV: Utilized for image processing tasks like reading, resizing, cropping, rotating, converting color spaces, applying filters, and encoding images.
Click this button to deploy the project to your Digital Ocean account:
To install image-manipulation-api-digitalocean, follow these steps:
Begin by cloning the repository containing the image-manipulation-api-digitalocean to your local machine.
git clone https://github.com/samestrin/image-manipulation-api-digitalocean/
Navigate to the project directory:
cd image-manipulation-api-digitalocean
Install the required dependencies using pip:
pip install -r src/requirements.txt
Endpoint: /api/resize
Method: POST
Resize an image to the specified width and height.
image
: Image filewidth
: Target width (integer)height
: Target height (integer)
Endpoint: /api/crop
Method: POST
Crop an image to the specified coordinates.
image
: Image filex1
: Starting x-coordinate of the crop area (integer)y1
: Starting y-coordinate of the crop area (integer)x2
: Ending x-coordinate of the crop area (integer)y2
: Ending y-coordinate of the crop area (integer)
Endpoint: /api/rotate
Method: POST
Rotate an image by the specified angle.
image
: Image fileangle
: Rotation angle in degrees (float)
Endpoint: /api/grayscale
Method: POST
Convert an image to grayscale.
image
: Image file
Endpoint: /api/brightness
Method: POST
Adjust the brightness of an image.
image
: Image filefactor
: Brightness adjustment factor (float)
Endpoint: /api/contrast
Method: POST
Adjust the contrast of an image.
image
: Image filefactor
: Contrast adjustment factor (float)
Endpoint: /api/flip
Method: POST
Flip an image horizontally or vertically.
image
: Image fileaxis
: Flip axis (horizontal
orvertical
)
Endpoint: /api/filter
Method: POST
Apply a filter to an image.
image
: Image filefilter_type
: Filter type (blur
,sharpen
, oredge_detect
)
Endpoint: /api/convert
Method: POST
Convert the format of an image.
image
: Image fileoutput_format
: Output format (e.g.,png
,jpeg
)
Endpoint: /api/list_fonts
Method: GET
List available fonts for adding text to images.
Endpoint: /api/add_text
Method: POST
Add text to an image.
image
: Image filetext
: Text to addfont
: Font type (integer)font_size
: Font size (integer)left
: Left position of the text (integer)top
: Top position of the text (integer)color
: Text color in RGB format (optional)
The API handles errors gracefully and returns appropriate error responses.
- 400 Bad Request: Invalid request parameters.
- 500 Internal Server Error: Unexpected server error.
The image-manipulation-api-demo project is a simple testing interface that utilizes Bootstrap and jQuery for AJAX-based interactions with the image-manipulation-api-digitalocean.
Contributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements.
This project is licensed under the MIT License - see the LICENSE file for details.