@jimp/plugin-contain
v2.2.2
Published
<div align="center"> <img width="140" alt="" src="https://raw.githubusercontent.com/jimp-dev/jimp/main/.github/assets/jimpy.png"> <h1>@jimp/plugin-contain</h1> <p>Contain an image within a height and width.</p> </div>
Readme
align places the image along each axis. It takes HorizontalAlign and VerticalAlign flags, or { x, y } fractions from 0 (left/top) to 1 (right/bottom), like CSS object-position percentages. An axis without a flag or fraction is centered, and fractions outside 0-1 are clamped:
import { Jimp, HorizontalAlign, VerticalAlign } from "jimp";
image.contain({
w: 150,
h: 100,
align: HorizontalAlign.LEFT | VerticalAlign.TOP,
});
// object-fit: contain; object-position: center 20%;
image.contain({ w: 150, h: 100, align: { x: 0.5, y: 0.2 } });Takes the same mode and premultiplyAlpha options as resize. With premultiplyAlpha: false the image is copied into the letter box as it is, rather than drawn over the background, so transparent pixels keep their colour.
See Getting Started to read an image, change it and save the result with write or getBuffer.
