Code Monkey home page Code Monkey logo

imageprocessor's Introduction

Image Processor

Class: CPSC-5200-01
Author: Mengshan Chen

A high level overview of the full system

architecture-2

Description of the architecture

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.

Communication protocols

This will be a REST API which is based on the HTTP protocol.

API overview

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

The file called "swagger.json" covers more details.

Sample Code

(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

Display

  • After run main files:
    Run

  • After run the demos:
    demo

Specification

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:

  • flip
    flip_v

  • rotate angle
    rotate_30

  • rotate left
    rotate_left

  • rotate right
    rotate_right

  • grayscale
    grayscale

  • thumbnail
    thumbnail

  • flip horizontal, grayscale
    flip_h,grayscale

Explanation of implementation

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.

Other consideration

Because this API specifies the format of transform, the API will return an error (400) if the client request does not meet this requirement.

imageprocessor's People

Contributors

mengshanchen avatar

Watchers

James Cloos avatar

imageprocessor's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.