New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

parse-cloud-image

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-cloud-image

Parse Server Cloud module for image manipulation using sharp

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Parse Cloud Image

Parse Cloud module for image manipulation using sharp

Getting started

Install the module by npm

$ npm i -S parse-cloud-image

or using yarn

$ yarn add parse-cloud-image

Resize image before save

Processing images can be done using the new file triggers on Parse Server introduced in version 4.2.0 All triggers can be found here

Define beforeSaveFile trigger:

import { ParseImage } from 'parse-cloud-image'

Parse.Cloud.beforeSaveFile(async (request: Parse.Cloud.FileTriggerRequest) => {
    const image = ParseImage.from(request.file)
    return image.resize(256)
})

Create ParseImage to make image manipulations. If the file is not an image file error will be thrown.

ParseImage

ParseImage wraps a ParseFile and provides several basic methods for manipulations:

Resize

When both a width and height are provided, aspect ratio will be preserve, ensure the image covers both provided dimensions by cropping/clipping to fit. For more options check sharp's documentation and use process method below

const image = ParseImage.from(parseFile)
image.resize(256, 128)

Rotate

Rotate the image by specified angle. For more options check sharp's documentation and use process method below

const image = ParseImage.from(parseFile)
image.rotate() // auto-rotated using EXIF Orientation tag

Scale

Scaling the image by specified factor. For more options check sharp's documentation and use process method below

const image = ParseImage.from(parseFile)
image.scale(1.0, 0.5)

Edit and process

These methods are the heart of the ParseImage giving elegant access to all capabilities of sharp over given ParseFile. Let's say you need to flip and rotate the image. This can be done like this:

const image = ParseImage.from(parseFile)
const processedImage = await image.edit(proc => proc.flip().rotate().toBuffer())
}

At the end the closure must return Buffer from the chain of actions which will be serialized as new ParseFile.

Advanced usage

In some cases you would need option to manipulate in parallel image or create multiple different changes on different clones of the image. This can be done with sharp and the process method of ParseImae providing a Sharp instances which can be piped.

const file = bucket.file("image.jpg").createWriteStream()
const image = ParseImage.from(parseFile)

...

image.process(sharp => sharp.resize(width, height)).pipe(file)

Keywords

FAQs

Package last updated on 01 Apr 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc