1.0.0 • Published 1 year ago

yair v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Yet Another Image Resizer

A somewhat opinionated image resizer.

Installation

yarn install yair

Usage

import { resizeImage } from 'yair';

resizeImage(imgBuffer);

Resize options

The following resize options are available:

URL ArgTypeDescription
wNumberMax width of the image.
hNumberMax height of the image.
qualityNumber, 0-100Image quality.
resizeString, "w,h"A comma separated string of the target width and height in pixels. Crops the image.
crop_strategyString, "smart", "entropy", "attention"There are 3 automatic cropping strategies for use with resize: attention: good results, ~70% slowerentropy: mediocre results, ~30% slowersmart: best results, ~50% slower
gravityStringAlternative to crop_strategy. Crops are made from the center of the image by default, passing one of "north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest" or "center" will crop from that edge.
fitString, "w,h"A comma separated string of the target maximum width and height. Does not crop the image.
cropBoolean|String, "x,y,w,h"Crop an image by percentages x-offset, y-offset, width and height (x,y,w,h). Percentages are used so that you don’t need to recalculate the cropping when transforming the image in other ways such as resizing it. You can crop by pixel values too by appending px to the values. crop=160px,160px,788px,788px takes a 788 by 788 pixel square starting at 160 by 160.
zoomNumberZooms the image by the specified amount for high DPI displays. zoom=2 produces an image twice the size specified in w, h, fit or resize. The quality is automatically reduced to keep file sizes roughly equivalent to the non-zoomed image unless the quality argument is passed.
webpBoolean, 1Force WebP format.
lbString, "w,h"Add letterboxing effect to images, by scaling them to width, height while maintaining the aspect ratio and filling the rest with black or background.
backgroundStringAdd background color via name (red) or hex value (%23ff0000). Don't forget to escape # as %23.