Class: CPSC-5200-01
Author: Mengshan Chen
Since transformation should run quickly and the users do not need to wait for a long time, the architecture will focus on using the service memory. Here is how it works: Clients will send requests with a image and a list of image transforms as part of the HTTP body through HTTPS to the API serivce. The service receives the request, maps the endpoint, identifies the operations in the request and execute the transforms in order on the in-memory image. At last, the service sends the image back through HTTPS so that the client can download it.
This will be a REST API which is based on the HTTP protocol.
- URL: /imageProcessor
- Method: POST
- Parameters:
-name: "Transforms"
in: "formData"
description: "image operations"
required: true
type: "string"
-name: "file"
in: "formData"
description: "file to upload"
required: true
type: "file" - Responses:
- 200 (Success)
- 400 (Bad request)
- 200 (Success)
The file called "swagger.json" covers more details.
(please view the following files)
- Main files: “server.py” and “client.py”
- server.py: covers the API design
- client.py describes the format of requests, and how to send requests to the server.
- Demo files:
- demo.py: a web application to test the functionality
- index.html: UI
The API covers seven transforms. Assume that the client should combine operations into a string, and each one is separated by a comma without spaces and capitals. Also, each one should follow the following formats.
For example: flip_h,rotate_360,grayscale,w_400,h_500,rotate_left
Transfrom | Format |
---|---|
Flip Horizontal | flip_h |
Flip Vertical | flip_v |
Rotate Degree | rotate_angle |
Rotate Left | rotate_left |
Rotate Right | rotate_right |
Convert to grayscale | grayscale |
Resize width | w_length |
Resize height | h_length |
Thumbnail | thumbnail |
Use an image called "test.jpeg" in /static/images to show the transforms that serves as a proof of concept:
After receiving the requests, the API will check the format of the image. Legal file formats include “jpg”, “png” and “jpeg”. If the image meets the requirement, the API stores the original file in memory. If there already exists an image with the same file name, the file name of the coming image will be added the current datetime.
Then, this API service will use the design pattern called Iterator Pattern. Because all transforms are combined in order into a string, the API will split the string into a list, iterate through the list, identify each transform and call the corresponding helper functions to modify the image.
After transformation, a word “new” will be added to the file name so as to separate from the original file and then the modified image will be saved in memory. At last, the API sends this new image file to the user.
Because this API specifies the format of transform, the API will return an error (400) if the client request does not meet this requirement.