Giter VIP home page Giter VIP logo

content-aware-santa's Introduction

content-aware-santa

Flask service for liquid-rescaling images using ImageMagick inspired by http://contentawaresatan.com/, deployable on AWS API Gateway/Lambda.

Examples

before -> after

Requirements

  • ImageMagick 6 built with liblqr support.
    • On macOS these can be installed together with Homebrew by running brew install imagemagick@6 --with-liblqr.

Usage

Building Dockerfile.debian will result in an image with the service and its dependencies installed. This can be done with run_debian.sh. Alternately, the service can be run locally with python app.py after installing its dependencies. This starts an HTTP server, and you can begin making requests. Requests are POSTs to the root of the service, e.g. http://localhost:5000/, and are JSON blobs with the following fields:

One of:

  • image_base64 (string) - base64 string of the image to be rescaled
  • image_url (string) - URL of the image to be rescaled

Any of:

  • rescale_width (positive int) - optional final width percentage (relative to original width) for the image, default 50%
  • rescale_height (positive int) - optional final height percentage (relative to original height) for the image, default 50%
  • start_width (positive int) - valid only for animated GIFs, optional starting width percentage (relative to original width) for the image, default 100%
  • start_height (positive int) - valid only for animated GIFs, optional starting height percentage (relative to original height) for the image, default 100%

An example request might look like:

{
  "image_url": "https://i.imgur.com/NyuJLXs.gif",
  "rescale_width": 75,
  "rescale_height": 75,
  "start_width": 20,
  "start_height": 20
}

Deploying to AWS

The service can also be deployed to AWS as an API Gateway/Lambda service via Zappa. The Dockerfile in this repo will download and compile ImageMagick with liblqr support for use with Lambda. Run build_lambda.sh to build the docker image and copy the build contents to the current directory before using Zappa to deploy. NOTE: sufficiently large images can time out due to API Gateway's maximum timeout, see the issue for a potential solution.

content-aware-santa's People

Contributors

acmanderson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

content-aware-santa's Issues

Process images asynchronously

API Gateway's timeout is 30 seconds and cannot be changed, meaning a lot of requests time out before they can finish. This will probably need to respond to S3 and DynamoDB events (see https://github.com/Miserlou/Zappa#executing-in-response-to-aws-events). Steps might be as follows:

  1. Have endpoint to upload image to S3.
  2. Trigger image processing based on S3 object created event.
  3. Update DynamoDB entry for image when complete.
  4. Poll DynamoDB until image is complete, returning it to the user.

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.