# crop-node

> Crop transparent pixel from image in Node.js

Latest version **2.1.2** (published 2024-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install crop-node
pnpm add crop-node
yarn add crop-node
bun add crop-node
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2024-05-14 |
| First published | 2019-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | GMartigny |
| Maintainers | gmartigny |
| Keywords | trim, image, edge, cut, resize, transparent, opacity, pixel, remove |

## Links

- npm: https://www.npmjs.com/package/crop-node
- Repository: https://github.com/GMartigny/crop-node
- Homepage: https://github.com/GMartigny/crop-node#readme
- Issues: https://github.com/GMartigny/crop-node/issues
- Funding: https://github.com/GMartigny/crop-node?sponsor=1
- npm.io page: https://npm.io/package/crop-node

## Dependencies (2)

- [canvas](https://npm.io/package/canvas.md) ^2.11.2
- [crop-universal](https://npm.io/package/crop-universal.md) ^1.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2024-05-14
- 2.1.0 — 2020-01-29
- 2.0.0 — 2020-01-23
- 1.0.0 — 2019-12-26

## README

# crop-node

[![Package version](https://flat.badgen.net/npm/v/crop-node)](https://www.npmjs.com/package/crop-node)
[![Package size](https://flat.badgen.net/bundlephobia/minzip/crop-node)](https://bundlephobia.com/result?p=crop-node)

Crop all transparent pixel around an image's edges. ([CLI version](https://github.com/GMartigny/crop-node-cli))


## Installation

    npm install crop-node


## Usage

```js
import crop from "crop-node";
import { writeFileSync } from "fs";

// Path to an image file
const path = "path/to/image.png";
const options = {
    outputFormat: "png",
};
// Run the async function and write the result
(async () => {
    const cropped = await crop(path, options);
    // Write the file (for example)
    writeFileSync("cropped.png", cropped);
})();
```


## Documentation

### `crop(input, [options])`

| Name | Type | Default | Comment |
| --- | --- | --- | --- |
|input |`String\|any` |required |Path to the image to process or any [type supported by `Canvas.prototype.drawImage`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage#Parameters) |
|options |`Options` |(see below) |Some options |

### `options`

| Name | Type | Default | Comment |
| --- | --- | --- | --- |
|outputFormat |`String` |`"png"` |Format of the output image (`"png"` or `"jpeg"`) |

In addition, all [options of `detect-edges`](https://github.com/GMartigny/detect-edges#options) are supported.


## Related

 - CLI version [`crop-node-cli`](https://github.com/GMartigny/crop-node-cli)
 - Browser version [`crop-browser`](https://github.com/GMartigny/crop-browser)
 - Environment agnostic [`crop-universal`](https://github.com/GMartigny/crop-universal)


## License

[MIT](license)

---
_Source: https://npm.io/package/crop-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
