Portive

Portive Client

Resize API

The resize API helps with resizing images while maintaining the correct aspect ratio.

Static Methods

resizeIn

function resizeIn(
  size: { width: number; height: number }, // original image size
  bounds: { width: number; height: number } // bounding box
): { width: number; height: number } // image size in bounding box

Takes the original size of an image and a bounds size and returns a new size of the image constrained to within the bounds.

  • Preserves the aspect ratio
  • The returned size will never be larger than the size of the original image
import { resizeIn } from "@portive/client/resize"

const newSize = resizeIn(
  { width: 1000, height: 800 },
  { width: 100, height: 100 }
)
// => { width: 100, height: 80 }