https://github.com/samestrin/image-manipulation-api-digitalocean
A Python DigitalOcean App Platform based REST image manipulation API using Flask, NumPy, and OpenCV that runs in a Docker container.
https://github.com/samestrin/image-manipulation-api-digitalocean
api docker flask image image-processing numpy python python3 rest rest-api
Last synced: 4 months ago
JSON representation
A Python DigitalOcean App Platform based REST image manipulation API using Flask, NumPy, and OpenCV that runs in a Docker container.
- Host: GitHub
- URL: https://github.com/samestrin/image-manipulation-api-digitalocean
- Owner: samestrin
- License: mit
- Created: 2024-04-28T04:38:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-08T19:19:12.000Z (almost 2 years ago)
- Last Synced: 2025-01-22T17:46:52.242Z (about 1 year ago)
- Topics: api, docker, flask, image, image-processing, numpy, python, python3, rest, rest-api
- Language: Python
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# image-manipulation-api-digitalocean
[](https://github.com/samestrin/image-manipulation-api-digitalocean/stargazers) [](https://github.com/samestrin/image-manipulation-api-digitalocean/network/members) [](https://github.com/samestrin/image-manipulation-api-digitalocean/watchers)
 [](https://opensource.org/licenses/MIT) [](https://www.python.org/)
**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:
[](https://cloud.digitalocean.com/apps/new?repo=https://github.com/samestrin/image-manipulation-api-digitalocean/tree/main&refcode=2d3f5d7c5fbe)
### 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.
```bash
git clone https://github.com/samestrin/image-manipulation-api-digitalocean/
```
Navigate to the project directory:
```bash
cd image-manipulation-api-digitalocean
```
Install the required dependencies using pip:
```bash
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](https://github.com/samestrin/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
[](https://twitter.com/intent/tweet?text=Check%20out%20this%20awesome%20project!&url=https://github.com/samestrin/image-manipulation-api-digitalocean) [](https://www.facebook.com/sharer/sharer.php?u=https://github.com/samestrin/image-manipulation-api-digitalocean) [](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/samestrin/image-manipulation-api-digitalocean)