Code Monkey home page Code Monkey logo

aws-lambda-image's Introduction

aws-lambda-image

Build Status Code Climate npm version

An AWS Lambda Function to resize/reduce images automatically. When an image is put on AWS S3 bucket, this package will resize/reduce it and put to S3.

Requirements

  • node.js ( AWS Lambda working version is 0.10.26 )
  • make

Installation

Clone this repository and install dependencies:

$ git clone [email protected]:ysugimoto/aws-lambda-image.git
$ cd aws-lambda-image
$ npm install .

Packaging

AWS Lambda accepts zip archived package. To create it, run make lambda task simply.

$ make lambda

It will create aws-lambda-image.zip at project root. You can upload it.

Configuration

This works with config.json put on project root. There is config.json.sample as example. You can copy to use it.

$ cp config.json.sample config.json

Configuration is simple, see below:

{
  "bucket": "your-destination-bucket",
  "reduce": {
      "directory": "reduced"
  },
  "resizes": [
    {
      "size": 300,
      "directory": "resized/small"
    },
    {
      "size": 600,
      "directory": "resized/middle"
    },
    {
      "size": 900,
      "directory": "resized/large"
    }
  ]
}
  • bucket: [String] Destination bucket name at S3 to put processed image. If not supplied, it will use same bucket of event source.
  • reduce: [Object] Reduce setting.
    • directory: [String] Image directory path.
    • bucket: [Object] Destination bucket to override. If not supplied, it will use bucket setting.
  • resizes: [Array] Resize setting.
    • size: [Number] Image width.
    • directory: [String] Image directory path.
    • bucket: [Object] Destination bucket to override. If not supplied, it will use bucket setting.

If you want to check how this works with your configuration, you can use configtest:

$ make configtest

Complete / Failed hooks

You can handle resize/reduce process on success/error result on index.js. ImageProcessor::run will return Promise object, run your original code:

processor.run(config)
.then(function(proceedImages)) {

    // Success case:
    // proceedImages is list of ImageData instance on you configuration

    /* your code here */

    // notify lambda
    context.succeed("OK, numbers of " + proceedImages.length + " images has proceeded.");
})
.catch(function(messages) {

    // Failed case:
    // messages is list of string on error messages

    /* your code here */

    // notify lambda
    context.fail("Woops, image process failed: " + messages);
});

Image resize

  • ImageMagick (installed on AWS Lambda)

Image reduce

  • cjpeg
  • pngquant
  • pngout

License

MIT License.

Author

Yoshiaki Sugimoto

Image credits

Thanks for testing fixture images:

aws-lambda-image's People

Contributors

farfenugen avatar rodrigoalviani avatar toooni avatar ysugimoto avatar

Watchers

 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.