Giter Club home page Giter Club logo

imagetor's Introduction

imagetor

This function download PDF, PNG or JPEG file from the URL provided in the request, save the original file in a bucket on Google Cloud Storage, resize and apply watermark (only on images) where desidered. This function can also delete a file previously saved.

This is a Google Cloud Function. (Node.js 10)
This function accepts only POST requests.
The trigger is an HTTPS endpoint.
This function does NOT create the relative buckets if not present.
You can easily deploy this function via gcloud functions deploy.

For develop this Google Cloud Functions you may need to use the Functions Framework for Node.js.
Remember to have the credentials.json in the root directory of the project.
You have to configure your variables via config.json (See examples section).

Features

  • Save original PDF document
  • Save original image
  • Save resized image
  • Overlay watermark based on local images
  • Supported input image format: JPEG, PNG
  • Supported output image format: JPEG, WebP
  • base64 decode for source image
  • multiple resize same request
  • Supported special headers in the request to download the image

Changelog

v1.3.0

  • Node.js 10
  • Modified extension accepted in the request. jpg to jpeg
  • Bugfix. Response not properly handled.
  • Add support to webp format

Examples

Example config.json (Only token property is required)

{
    "mybucketname": {
        "token": "myauthtoken",
        "watermark": "mywatermarkpath",
        "auth_header": {
            "Authorization": "Bearer myauthtoken"
        }
    },
    "mysecondbucket": {
        "token": "mysecondtoken"
    }
}

Delete image

Request:

{
    "action": "del",
    "bucket": "mybucketname",
    "authToken": "myauthtoken",
    "relativePath": "test/ori.jpg"
}

Expected response:

{
    "OK": "deleted"
}

Save image without resizing and without watermark

Request:

{
    "url": "https://images.pexels.com/photos/106399/pexels-photo-106399.jpeg",
    "action": "add",
    "bucket": "mybucketname",
    "extension": "jpeg",
    "authToken": "myauthtoken",
    "originalImageRelativePath": "test/ori.jpg",
    "base64Format": true,
    "watermark": false
}

Expected response:

{
    "OK": [
        {
            "url": "https://storage.googleapis.com/mybucketname/test/ori.jpg"
        }
    ]
}

Save image with resizing and watermark

Request:

{
    "url": "https://images.pexels.com/photos/106399/pexels-photo-106399.jpeg",
    "action": "add",
    "bucket": "mybucketname",
    "extension": "jpeg",
    "authToken": "myauthtoken",
    "originalImageRelativePath": "test/ori.jpg",
    "base64Format": true,
    "watermark": true,
    "watermarkPosition": "center",
    "files": [
    {
        "width": 1154,
        "height": 739,
        "relativePath": "test/image1.jpg"
    },
    {
        "width": 1154,
        "height": 749,
        "relativePath": "test/image2.jpg"
    },
    {
        "width": 1154,
        "height": 759,
        "relativePath": "test/image3.jpg"
    }
    ]
}

Expected response:

{
    "OK": [
        {
            "url": "https://storage.googleapis.com/mybucketname/test/ori.jpg"
        }
    ]
}

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.