# image-minify-client

> JavaScript module for running image optimization in web browser.

Latest version **1.0.1** (published 2022-04-30) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install image-minify-client
pnpm add image-minify-client
yarn add image-minify-client
bun add image-minify-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-04-30 |
| First published | 2021-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | niceplugin |
| Maintainers | niceplugin |
| Keywords | image, compression, optimization, minify, resize, client, browser |

## Links

- npm: https://www.npmjs.com/package/image-minify-client
- Repository: https://github.com/niceplugin/image-minify-client
- Issues: https://github.com/niceplugin/image-minify-client/issues
- npm.io page: https://npm.io/package/image-minify-client

## 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.1 (latest) — 2022-04-30
- 0.1.4 — 2021-07-24
- 0.1.3 — 2021-07-23

## README

- [English](https://github.com/niceplugin/image-minify-client)
- [한국어](https://github.com/niceplugin/image-minify-client/blob/main/readme.ko.md)

* * *

# Image Minify Client

**Image Minify Client** scales down by removing metadata from the browser and adjusting quality using canvas APIs.

It was created to reduce bandwidth and server CPU load. :)

## Demo website

[imageMinify](https://imageminify.com/)

## Note

- Support input type only `bmp`, `png`, `gif`, `jpeg`, `webp`
- Support output type only `jpeg` and `webp`
- Loses animation if it has animation

## Install

```shell
npm install image-minify-client
```

## Quickstart example code

```html
<img id="img" src="" alt="">
<input id="input" type="file">
```

```js
import imc from "image-minify-client"

const img = document.getElementById('img')
const input = document.getElementById('input')

input.addEventListener('change', event => {
  const file = event.target.files[0]
  
  if (!file) { return }

  imc(file).then(rslt => {
    const newFile = rslt[0]
    const oldFile = rslt[1]

    img.src = URL.createObjectURL(newFile)

    console.log(newFile, oldFile)
  })
})
```

## Usage

### Syntax

```
module(File[, options])
```

### Parameter

#### File
Require. Image object of file type.

#### options
Optional.
- quality : (default: `0.8`) Number in the `0` < value <= `1` range.
- maxWidth : (default: `undefined`) Greater then `0`. If the width of the image is greater than maxWidth, the width is adjusted to maxWidth while maintaining the proportions.
- maxHeight : (default: `undefined`) Greater then `0`. If the height of the image is greater than maxHeight, the height is adjusted to maxHeight while maintaining the proportions.
- outputType : (default: `jpeg`) String `jpeg` | `webp`

#### Return

Since this method is asynchronous, it returns a `promise`. In case of `resolve`, an array of `File` objects is returned as shown below.

`[ newFile , oldFile ]`

#### Syntax

```js
imc(File, {
  quality: 0.75,
  maxHeight: 300,
  outputType: 'webp'
}).then(result => {
  console.log('Before minify file: ', result[1])
  console.log('After minify file: ', result[0])
})
```
#### error

If an error occurs during operation, an object such as `{ code: number, message: string }` is returned as an error. Even with the same error code, the message may be different. Details are as follows.

| Code | Message                                       |
|------|-----------------------------------------------|
| 400  | The first parameter cannot be empty.          |
| 400  | The first parameter is not a File type.       |
| 404  | The image could not be loaded.                |
| 409  | The process is already running.               |
| 412  | Failed to minify image.                       |
| 413  | Image is over than the size supported.        |
| 415  | The first parameter is not a Image File type. |
| 415  | "${ fileFormat }" format is not support       |
| 501  | Does not support modules.                     |

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