Skip to content

Sharp for Image Crop Demo

Crop images to specific dimensions using Sharp.

Usage

The crop operation extracts a region from an image. Specify the width, height, and optional offsets to control the cropping area.

Parameters

  • width: Width of the crop area in pixels
  • height: Height of the crop area in pixels
  • left: Left offset (optional, default: 0)
  • top: Top offset (optional, default: 0)

Example

javascript
await sharp('input.jpg')
  .extract({ left: 100, top: 50, width: 800, height: 600 })
  .toFile('cropped.jpg');

Released under the Apache 2.0 License.