NodeJS
π Installation
npm install @chakata/pichax
# or
yarn add pichaxExample
import { PichaX } from '@chakata/pichax';
const picha = new PichaX('your_api_key', 'your_api_secret');
// π Transform an image
const transformUrl = picha.transform({
id: 'img_123',
expires: '1725168000', // Unix timestamp
src: 'https://example.com/image.jpg',
cache: false, // Not required. Default: true
params: {
"rotate": {"degrees": 45},
"resize": {"w": 100, "h": 200, "mode": "fill"}, // Modes: "fit", "fill", "crop"
// Resize options:
// {"scale": 0.5} -- This will scale image to 50% of the original size
// {"w": 100} -- This will keep aspect ratio
"effects": [{"grayscale": true}, {"blur": 10}, {"sharpen": true}],
"format": "jpeg", // Options are: "webp", "jpeg", "png"
"quality": 80, // 0 - 100
"watermark": {"text": "Hello there"},
// custom watermarks are only supported in production key
// a default watermark is applied otherwise
"crop": {"x": 100,"y": 30,"w": 100,"h": 20}
// Crop options:
// {"w": 100, "h", 200, "mode": "centre"} -- Modes: "centre", "attention", "entropy"
}
}).getUrl();
console.log(transformUrl);
// π€ Generate an identicon
const identiconUrl = picha.identicon({
id: 'user_123',
expires: '1725168000',
name: 'PichaX'
}).getUrl();
console.log(identiconUrl);π Signature Generation
All URLs include a signature for security, generated using HMAC-SHA256:
π§° Transformations
Each transformation is optional and can be combined:
β
Type Safety
This SDK is written in TypeScript and includes full type definitions out of the box.
Last updated