simple-cloudinary
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

Simple Cloudinary !

This is an abstraction of cloudinary api to improve development by TypeScript object.

Thirst, you must create an account to Cloudinary cloudinary And after... Enjoy !


How to use ?

Install module :

npm install --save damiengilbrin/cloudinary-transformation

Require a cloudinary object and his configuration like Cloudinary documentation - Nodejs intégration

let cloudinary = require('cloudinary');
cloudinary.config({
    cloud_name: 'sample',
    api_key: '874837483274837',
    api_secret: 'a676b67565c6767a6767d6767f676fe1'
});

Upload file to cloudinary (see Cloudinary documentation)

Make an instance of simpleCloudinary :

let simpleCloudinary = require('./index')(cloudinary);

Make an image by Json Object

If you want you can put an object configuration like Json :

let imageUrl = simpleCloudinary.createFromJsonObject(
    'MyImageNameUploadedToCloudinary',
    [
        {
            type: 'rotate',
            enabled: true,
            parameters: {
                angle: -30
            }
        },
        {
            type: 'crop',
            enabled: true,
            parameters: {
                x: 10,
                y: 50,
                width: 500,
                height: 400
            }
        }
    ],
    {
        text: 'Created by Damien Gilbrin',
        fontSize: 15,
        fontFamily: 'Trebuchet MS',
        fontStyle: 'normal',
        fontWeight: 'bold',
        fontColor: {
            red: 255,
            green: 255,
            blue: 255,
            alpha: 1
        },
        backgroundColor: {
            red: 0,
            green: 0,
            blue: 0,
            alpha: 0.75
        },
        gravity: {
            direction: 'south_west',
            offset_x: 10,
            offset_y: 10
        }
    }
).getUrl(200,200)

createFromJsonObject(imageId, transformations, signature) : UrlGenerator

Functions parameters :

  • imageId (string) : Name of image on cloudinary
  • transformations (array of object) : A collection of transformation
  • signature(object|false) : a signature object to make a signature or false if no sign Will return an object a UrlGenerator class

transformation Objects parameters :

  • type (string) : type of transformation :
    • 'rotate' to rotate an image. The parameters parameters must have this :
      • angle (number) : degres of rotate
    • 'crop' to cut an image from x and y point and width and height. The parameters parameters must have this :
      • x (number) : Start position to cut image x
      • y (number) : Start position to cut image y
      • width (number) : Width of new image crop from x
      • height (number) : Height of new image crop from y
  • enabled (boolean) : If true, the current transormation is apply
  • parameters (object) : List of parameters of transformation, see type for more informations

signature Objects parameters :

  • text (string) : Message of signature, eq "Created by Damien Gilbrin"
  • fontSize (nulmber) : Font size at pixel
  • fontFamily (string) : Font family name, eq "Arial"
  • fontStyle (string) : A font style like "italic"
  • fontWeight (string) : A font weight like "bold"
  • fontColor (object) : A color object of font coloration
  • backgroundColor (object) : A color object of background coloration
  • gravity (object) : a gravity object

color Objects parameters :

  • red (number) : A red color 0 to 255
  • green (number) : A red color 0 to 255
  • blue (number) : A red color 0 to 255
  • alpha (number) : A rate of alpha 0 to 1. (1 is totaly visible)

gravity Objects parameters :

  • direction (string) : Name of direction gravity : 'south_west', 'south', 'south_east', 'north_west', 'north', 'north_east'
  • `offset_x (number) : Offset x of gravity, default 0 pixel
  • `offset_y (number) : Offset y of gravity, default 0 pixel

UrlGenerator class :

This class containe this method : getUrl(width: number, height: number): string

You call this methode to generate an Url for this configuration width and height pixel. It will return a signed url string of cloudinary


createFromImageObject(imageId) : ImageManipulation

(documentation soon)

Readme

Keywords

Package Sidebar

Install

npm i simple-cloudinary

Weekly Downloads

0

Version

0.5.1

License

ISC

Last publish

Collaborators

  • damiengilbrin