@imageproc/cloud-functions
TypeScript icon, indicating that this package has built-in type declarations

0.0.14 • Public • Published

@imageproc/cloud-functions

Process images on Google Cloud Storage when images are created.

How to use?

  1. Prepare your Google Cloud Functions directory.
functions
  |- package.json
  |- index.js
  |- .gcloudignore
 ...
  1. Install @imageproc/cloud-functions
npm install @imageproc/cloud-functions
  1. Handle stroage trigger

You can use handleStorageObjectCreated(params: InitParams) to initialize trigger. The followings are the property of InitParams:

  • sourceBucket?: string
    • Source bucket of images
    • This is optional property. If not set, use trigger bucket as the source bucket.
  • destBucket?: string
    • Destination bucket of generated images
    • This is optional property. If not set, use trigger bucket as the source bucket.
  • ignoreNamePattern?: RegExp
    • Pattern of object name to be ignored.
    • If sourceBucket and destBucket is same, this property is REQUIRED to avoid infinite loop processing.
  • destNamePrefix?: string
    • Prefix of destination object name
  • destNameTransform?: (sourceName: string) => void
    • Function to transfrom object name
    • If this property is set, destNamePrefix property will be ignored.
  • operation: Operation

Examples:

  • Using event target bucket for both source and destination.
const imageproc = require("@imageproc/cloud-functions");
// foo.jpg => files/foo.jpg
exports.processImage = imageproc.handleStorageObjectCreated({
    ignorePattern: /^files\//,
    destNamePrefix: "files/",
    opration: {
        name: "resizeAspectFit",
        params: {
            maxWidth: 2000,
            maxHeight: 2000,
            noScaleUp: true
        }
    }
});
  • Using other buckets for source and destination.
const imageproc = require("@imageproc/cloud-functions");
exports.processImage = imageproc.handleStorageObjectCreated({
    sourceBucket: "source-image",
    destBucket: "dest-images",
    ...
});
  1. Deploy
gcloud functions deploy processImage \
--runtime nodejs10 \
--trigger-resource YOUR_BUCKET \
--trigger-event google.storage.object.finalize \
--memory 2048MB \ # recommended
--project YOUR_PROJECT

Readme

Keywords

none

Package Sidebar

Install

npm i @imageproc/cloud-functions

Weekly Downloads

0

Version

0.0.14

License

MIT

Unpacked Size

7.71 kB

Total Files

4

Last publish

Collaborators

  • argano
  • nabeix