GithubHelp home page GithubHelp logo

einselbst / lambda-image-sharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaikant/lambda-image-sharp

0.0 1.0 0.0 40.94 MB

Image resizing using lambda and sharp, to generate srcSet and Sizes for webpages

Dockerfile 0.77% Shell 5.21% JavaScript 94.02%

lambda-image-sharp's Introduction

Lambda Image Sharp

This lambda service resizes images. It generates multiple images of different sizes which could be used in the srcSet and sizes attributes in webpages.

To Deploy

serverless deploy -v

  1. Given an image and a desirable width (say w), it will create 6 images which are of width: 1/4w, 1/2w, w, 1.5w, 2w, and 3w

These image sizes can be used to provide optimised images on a website using the img html tag along with the sizes attributes.

  1. Given an image and a desirable width (say w), it will create 4 images which are of width: w, 1.5w, 2w and 3w These images can then be used in the srcSet as srcSet = "urlofimage1 1x, urlofimage2 1.5x, urlofimage3 2x, urlofimage4 3x" For responsive images, set the transformtype to be 'responsive' in the imgconfig.json

Example: Lets say you want images of width : '200', '400', '800', '1200', '1600', '2400'

Update the imgconfig.json file:

  "output" : {
    "default" : {
       "outputdir": "defaulttest/",
       "maxWidth": "800"
     },
    "cover" : {
       "outputdir": "cover/",
       "maxWidth": "800",
     }
  }

In the above we are telling the service:

  • If the picture is in the input bucket, in a folder named "cover", then the resized image should go to a folder called "cover" in the output bucket.
  • Create images with the wdth assumed to be 800.

This then creates images with the width of 200, 400, 800, 1200, 1600 & 2400.

In your app/html you can dynamically evaluate the srcSet:


   let sizesArray=['200', '400', '800', '1200', '1600', '2400']
   let scSet;

   srcSet = sizesArray.map((size) => {
       return `urlofyourpicture ${size}w`
     }).reduce((total, value) => `${total},${value}`);
   }

Pass the srcSet to your images tag to get optimised pictures.

Documentation:

image.js It receives the initial events in processItem. It returns an array of promises, each promise resolves to one processed file It invokes the get from s3 It invokes the sharp API It invokes the uploads to s3

s3.js It has default source and destination buckets. It implements the get from s3. It implements the uploads to s3.

sharp.js The sharp APIs

This is inspired by https://github.com/adieuadieu/serverless-sharp-image & https://github.com/gatsbyjs/gatsby/tree/4bc96cf82cee87f8e2d90a08a3db99ad96783ffd/packages/gatsby-plugin-sharp

lambda-image-sharp's People

Contributors

einselbst avatar jaikant avatar

Watchers

 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.