🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

lambda-image

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

lambda-image

Lambda Image Class for easy image manipulation on AWS Lambda

unpublished
latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source


lambda-image

Version Version

Issues Stars Open PRs License

Dependencies DevDependencies PeerDependencies

Install Size Publish Size

Build Status

Code Coverage

Technical Debt Maintainability Coverage

Lambda Image is a simple image class to allow to easily manipulate images on AWS Lambda

WARNINGS

If you wish to download an image from a url, you must install got as a package in your project.

If you wish to be able to load and save to s3, (and you aren't on aws lambda) you must install aws-sdk as a package in your project.

If you are testing locally, ensure you have imagemagick installed

Getting Started

const lambdaImage = require('lambda-image');

const image = await lambdaImage('/path/to/image.png');

const { height, width } = await image.getDimensions();

const resizedImage = await lambdaImage(await image.resize(512, 512));

await resizedImage.save({ bucket: 's3bucket', key: await resizeImage.getHashKey() });

lambdaImage(loadInfo, loadOptions)

Returns a image object. Must be called with await

loadInfo can be either a

  • buffer
  • object with { bucket, key } for an s3 file
  • base64 image with data:{contentType};base64 prefix
  • url
  • file path

If a url is provided, you must provide the got library in your dependecies.

loadOptions is an object that can contain a profile of your aws credentials

const options = {
	profile: 'default',
};

API

  • image.crop(width, height, gravity) Returns the buffer for the image when crop is applied
  • image.getContentType() Get the mime type
  • image.getDimensions() Get the dimensions in an object { height, width }
  • image.getExt() Get the image extension
  • image.getHash() Get the md5 hash of the image
  • image.getHashKey() Get the save key based on the md5 hash 2C2A8686BFA31A2AE5F55A7F60009E14 => 2/C/2C2A8686BFA31A2AE5F55A7F60009E14.png
  • image.getHeight() Get the height of the image
  • image.getSize() Get the image file size in bytes
  • image.getType() Get the image extension
  • image.getWidth() Get the width of the image
  • image.identify() Get the data from imagemagick identify
  • image.quality(percentage) Returns the buffer for the image when quality of percentage is applied
  • image.resize(width, height) Returns the buffer for the image when resized to width / height - Does not crop
  • image.resizeAndCropCenter(width, height) Returns the buffer for the image when resized to width / height after cropping
  • image.rotate(degrees, color) Returns the buffer for the image when rotated. Color is used to fill in background color (defualts to transparent)
  • image.save(saveInfo, saveOptions = loadOptions) Saves the image based on the saveInfo and saveOptions
  • image.toBase64() Converts the image to base64 with the data:{contentType};base64 prefix
  • image.toBase64Binary() Converts the image to base64 without the data:{contentType};base64 prefix
  • image.toBuf() Converts the image to a buffer

image.save(saveInfo, saveOptions)

saveInfo can be either a

  • object with { bucket, key } to save to an s3 bucket
  • file path

loadOptions is an object that can contain a profile of your aws credentials. This will default to saveOptions

const options = {
	profile: 'default',
};

FAQs

Package last updated on 23 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts