@ppsh-ui/image-tools
v0.1.4
Published
Tiny browser image utils (rotate, grayscale, threshold, brightness/contrast, crop, fit-to-page).
Downloads
9
Readme
@ppsh-ui/image-tools
Tiny browser image utils for rotating, grayscale, threshold, brightness/contrast, cropping, and fitting images to page using canvas.
Features
- Rotate images by any angle
- Apply grayscale filter
- Apply black & white threshold
- Adjust brightness and contrast
- Crop images to a rectangle
- Fit images to A4 page size
Install
npm i @ppsh-ui/image-toolsUsage
import {
rotateBlob,
applyGrayscale,
applyThresholdBW,
adjustContrast,
adjustBrightness,
cropBlob,
fitToPage,
Rect
} from "@ppsh-ui/image-tools";
// Rotate an image blob by 90 degrees
const rotated = await rotateBlob(fileBlob, 90);
// Convert image blob to grayscale
const gray = await applyGrayscale(fileBlob);
// Apply black & white threshold
const bw = await applyThresholdBW(fileBlob, 128);
// Adjust contrast [-100..100]
const contrast = await adjustContrast(fileBlob, 50);
// Adjust brightness [-100..100]
const bright = await adjustBrightness(fileBlob, 30);
// Crop image blob to rectangle
const rect: Rect = { x: 10, y: 10, width: 100, height: 100 };
const cropped = await cropBlob(fileBlob, rect);
// Fit image to A4 page (default 2480x3508 px at 300dpi)
const fitted = await fitToPage(fileBlob);API
See src/index.ts for full API documentation.
License
MIT
