0.0.14 • Published 3 years ago

@imageproc/cloud-functions v0.0.14

Weekly downloads
10
License
MIT
Repository
-
Last release
3 years ago

@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
0.0.14

3 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago