Skip to content

A Python DigitalOcean App Platform based REST image manipulation API using Flask, NumPy, and OpenCV that runs in a Docker container.

License

Notifications You must be signed in to change notification settings

samestrin/image-manipulation-api-digitalocean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image-manipulation-api-digitalocean

Star on GitHub Fork on GitHub Watch on GitHub

Version 0.0.2 License: MIT Built with Python

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.

Dependencies

  • 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.

Deploy to DigitalOcean App Platform

Click this button to deploy the project to your Digital Ocean account:

Deploy to DO

Installation

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

Endpoints

Resize Image

Endpoint: /api/resize Method: POST

Resize an image to the specified width and height.

Parameters

  • image: Image file
  • width: Target width (integer)
  • height: Target height (integer)

Crop Image

Endpoint: /api/crop Method: POST

Crop an image to the specified coordinates.

Parameters

  • image: Image file
  • x1: 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)

Rotate Image

Endpoint: /api/rotate Method: POST

Rotate an image by the specified angle.

Parameters

  • image: Image file
  • angle: Rotation angle in degrees (float)

Convert to Grayscale

Endpoint: /api/grayscale Method: POST

Convert an image to grayscale.

Parameters

  • image: Image file

Adjust Brightness

Endpoint: /api/brightness Method: POST

Adjust the brightness of an image.

Parameters

  • image: Image file
  • factor: Brightness adjustment factor (float)

Adjust Contrast

Endpoint: /api/contrast Method: POST

Adjust the contrast of an image.

Parameters

  • image: Image file
  • factor: Contrast adjustment factor (float)

Flip Image

Endpoint: /api/flip Method: POST

Flip an image horizontally or vertically.

Parameters

  • image: Image file
  • axis: Flip axis (horizontal or vertical)

Apply Filter

Endpoint: /api/filter Method: POST

Apply a filter to an image.

Parameters

  • image: Image file
  • filter_type: Filter type (blur, sharpen, or edge_detect)

Convert Image Format

Endpoint: /api/convert Method: POST

Convert the format of an image.

Parameters

  • image: Image file
  • output_format: Output format (e.g., png, jpeg)

List Fonts

Endpoint: /api/list_fonts Method: GET

List available fonts for adding text to images.

Add Text to Image

Endpoint: /api/add_text Method: POST

Add text to an image.

Parameters

  • image: Image file
  • text: Text to add
  • font: 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)

Error Handling

The API handles errors gracefully and returns appropriate error responses.

  • 400 Bad Request: Invalid request parameters.
  • 500 Internal Server Error: Unexpected server error.

Frontend/Testing Interface

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.

Contribute

Contributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Share

Twitter Facebook LinkedIn

About

A Python DigitalOcean App Platform based REST image manipulation API using Flask, NumPy, and OpenCV that runs in a Docker container.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published