Code Monkey home page Code Monkey logo

image-service's Introduction

Image Processing Service

Build Status Coverage Status

This micro-service is used for calling Sharp pipelines on supplied images and then uploading the result to an S3 compliant endpoint or local storage. Images are streamed to a file, transformed and then streamed to the endpoint to minimize memory usage during upload.

Configuration

Configuration is stored in the config.yaml file in the top directory of this project, you can override this by using the CONFIG_FILE environment variable. Additionally environment variables can be used inside the configuration file by using the spring like ${VARIABLE} syntax.

To configure uploading to aws the following YAMl could be used:

port: 8080
uploadDirectory: /tmp/uploaded_files
upload:
  bucket: ${AWS_BUCKET}
  key: ${AWS_KEY}
  secret: ${AWS_SECRET}
  endpoint: ${AWS_ENDPOINT}
  pathStyle: ${AWS_PATH_STYLE}

To configure copying to a local directory the following YAMl could be used:

port: 8080
uploadDirectory: /tmp/uploaded_files
upload:
  saveDirectory: /images/

Usage

To use this micro-service two variables pipeline and image need to be POST'ed to the route "/". Starting this service and a minio instance for testing can be done using docker compose.

docker-compose up

Resize an image:

curl -F "pipeline=[ { \"resize\" : [ 20, 20 ]} ]" -F "image=@/Users/me/my-image.jpg" http://127.0.0.1:8080/

Convert an uploaded image to WEBP:

curl -F "pipeline=[ { \"webp\" : {} } ]" -F "image=@/Users/me/my-image.jpg" http://127.0.0.1:8080/

Multiple stages can be defined (as with Sharp), remember the order matters!

curl -F "pipeline=[ { \"resize\" : [ 200, 200 ]}, { \"rotate\": [90] }, { \"jpeg\" : { \"quality\" : 100 } } ]" -F "image=@/Users/me/my-image.jpg" http://127.0.0.1:8080/

Deployment

You can deploy the image service to a kubernetes cluster using the sample deployment configuration.

kubectl apply -f image-service.yaml

The following Sharp methods are supported, usage can be found in the Sharp docs:

  • resize
  • crop
  • embed
  • max
  • min
  • ignoreAspectRatio
  • withoutEnlargement
  • rotate
  • extract
  • flip
  • flop
  • sharpen
  • median
  • blur
  • extend
  • flatten
  • trim
  • gamma
  • negate
  • normalise
  • normalize
  • convolve
  • threshold
  • linear
  • background
  • greyscale
  • grayscale
  • toColourspace
  • toColorspace
  • jpeg
  • png
  • webp
  • tiff
  • raw

Docker Environment Variables

Variable Usage
AWS_BUCKET The S3 bucket images should be uploaded/downloaded from.
AWS_KEY AWS key.
AWS_SECRET AWS Secret.
AWS_ENDPOINT AWS S3 endpoint, for example http://127.0.0.1:9000
AWS_PATH_STYLE Enable/disable force path style for AWS client, is required by some S3 compliant providers.
PORT The port this service listens on.
UPLOAD_DIR The directory within this container images are uploaded and transformed in.

Performance/Resources

Testing using Apache jMeter with 100 threads, sending a 5MB file 100 times each showed the following:

CPU RAM Storage Requests/s
2 cores of 2.9 GHz Intel Core i7 @ 100% 100-200MB 55B-200MB 35~

image-service's People

Contributors

lewisgcm avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.