NodeJS

πŸš€ Installation

npm install @chakata/pichax
# or
yarn add pichax

Example

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: 90 },
    resize: { scale: 0.8 },
    flip: { direction: 'vertical' },
  }
}).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:

HMAC_SHA256(unique_key + ":" + expires, api_secret)

🧰 Transformations

Each transformation is optional and can be combined:

params: {
  rotate: { degrees: 90 },              // 0 - 360
  resize: { scale: 0.5 },               // 0 < scale <= 1
  flip: { direction: 'horizontal' },    // 'horizontal' | 'vertical'
  grayscale: true,
  crop: {x: 100, y: 100, w: 200, h: 300},
  // crop: { w: 200, h: 300 }
  // crop: { type: "frontal_face" } Uses AI to detect front looking face
}

βœ… Type Safety

This SDK is written in TypeScript and includes full type definitions out of the box.

Last updated