# crop-universal

> Crop transparent pixel from image

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

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

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

## Links

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

## Dependencies (1)

- [detect-edges](https://npm.io/package/detect-edges.md) ^1.0.1

## 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

- 1.0.2 (latest) — 2024-05-14
- 1.0.1 — 2020-02-11
- 1.0.0 — 2020-01-29

## README

# crop-universal

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

Crop all transparent pixel around an image's edges.

⚠️ This package is environment agnostic. It requires you to provide a `Canvas` implementation. It'll be more simple for you to use:
 - For browsers 👉 [`crop-browser`](https://github.com/GMartigny/crop-browser)
 - For Node.js 👉 [`crop-node`](https://github.com/GMartigny/crop-node)
 - As a CLI 👉 [`crop-node-cli`](https://github.com/GMartigny/crop-node-cli)


## Installation

    npm install crop-universal


## Usage

```js
import crop from "crop-universal";

// You're in charge of providing a couple of function corresponding to your environment
const cropper = crop({ createCanvas, loadImage });

const url = "path/to/file.png";
const canvas = cropper(url);
```


## Documentation

### `crop(environment)`

| Name        | Type     | Default  | Comment                                                          |
|-------------|----------|----------|------------------------------------------------------------------|
| environment | `Object` | required | Object holding a `createCanvas` and a `loadImage` implementation |

This will return a `Function` that you can use to crop.

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

| Name    | Type                              | Default     | Comment                                                                                             |
|---------|-----------------------------------|-------------|-----------------------------------------------------------------------------------------------------|
| input   | `String\|Image\|HTMLImageElement` | required    | Path to the image to process or any type supported by your `Canvas.prototype.drawImage` environment |
| options | `Options`                         | `undefined` | Allow to forward [options to `detect-edges`](https://github.com/GMartigny/detect-edges#options)     |

This will return a canvas with the result drawn onto.


## License

[MIT](license)

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