Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chijete/crafyimagecompressjs

In-browser javascript image compression library (GIF, JPG, PNG, WEBP)
https://github.com/chijete/crafyimagecompressjs

gif-compression gif-compressor image-compression image-compressor image-compressor-js javascript-image

Last synced: 7 days ago
JSON representation

In-browser javascript image compression library (GIF, JPG, PNG, WEBP)

Awesome Lists containing this project

README

        

# CrafyImageCompressJS

In-browser javascript image compression and resizing library with support for static images (JPG, PNG, WEBP) and animated GIFs, with and without transparency.

- Resize image with maximum width and maximum height.
- Compress image quality to reduce size.

Principal class `CrafyImageCompressJS` it's inside `CrafyImageCompressJS.js` file.
## Installation

Download `CrafyImageCompressJS.js` and `gif.worker.js` (more info in Class Reference section).

```

```

## Class Reference

#### Create new instance of class.

```
new CrafyImageCompressJS(image, image_type)
```

| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `image` | `blob` | **Required**. Image Blob (PNG, JPG, WEBP, GIF) |
| `image_type` | `string` | **Required**. Image mime type (example: "image/png") |
| `gifjs_workerScript_url` | `string` | **Optional**. gif.js workerScript URL (link to `gif.worker.js` file) |

**Returns:** `true`.

#### Compress the image.

```
compressImage(quality, maxWidth, maxHeight)
```

| Parameter | Type | Description |
| :-------- | :------- | :-------------------------------- |
| `quality` | `float` | **Required**. Target quality from 0 to 1 (0 is lower quality and 1 is better quality, example: 0.6). |
| `maxWidth` | `float` | **Optional**. Result image maximum width in pixels. |
| `maxHeight` | `float` | **Optional**. Result image maximum height in pixels. |
| `maxWidthForGIF` | `float` | **Optional**. Result image maximum width in pixels (only for GIFs). |
| `maxHeightForGIF` | `float` | **Optional**. Result image maximum height in pixels (only for GIFs). |

**Returns:** `Blob Image` ("image/gif" for GIF input, "image/webp" for everyone else).