Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/datsteves/image-optimizer-core
This Package optimizes your images by adjusting the quality automatically
https://github.com/datsteves/image-optimizer-core
compression image-compression image-optimization imagemin jpg opencv optimizer png webp
Last synced: about 2 months ago
JSON representation
This Package optimizes your images by adjusting the quality automatically
- Host: GitHub
- URL: https://github.com/datsteves/image-optimizer-core
- Owner: datsteves
- License: mit
- Archived: true
- Created: 2018-02-01T14:22:27.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-04T12:05:06.000Z (about 6 years ago)
- Last Synced: 2024-09-23T23:31:04.362Z (about 2 months ago)
- Topics: compression, image-compression, image-optimization, imagemin, jpg, opencv, optimizer, png, webp
- Language: JavaScript
- Homepage:
- Size: 15 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Image Optimizer Core
[![Build Status](https://travis-ci.com/datsteves/image-optimizer-core.svg?branch=master)](https://travis-ci.com/datsteves/image-optimizer-core)
This Package optimizes your images and adjust the quality automatically.
So no standard 80% Quality on your JPEG's.## Install
please have a look at the instruction of [node-opencv](https://github.com/peterbraden/node-opencv) to install opencv on your machine.
```bash
$ npm install image-optimizer-core
# or with yarn
$ yarn add image-optimizer-core
```## Usage
```js
import optimizer from 'image-optimizer-core'
// or with the old way
// const optimizer = require('image-optimizer-core')// using files
optimizer('path/to/file.jpg')
.toFile('output.jpg')
.then(saved => {
console.log('I saved you', saved * 100, '%')
})// using Buffer
optimizer(buffer)
.toBuffer()
.then(output => {
// ...
})// You even get the saved kb back as a percentage
optimizer('example.jpg')
.toBuffer()
.then((buffer, saved) => {
console.log('saved', saved, '%') // 0.72345 ... so it saved you 72.345%
})// or if you want, you can even convert your files
optimizer('example.png')
.toBuffer('image/webp')
.then((buffer, saved) => {
console.log('saved', saved, '%') // 0.72345 ... so it saved you 72.345%
})```
## API
### optimizer(input)
Returns `toBuffer` and `toFile`
#### input
Type: `Buffer` or `String`
### toBuffer(outputType)
Returns `Promise, `
### toFile(ouputPath, outputType)
Returns `Promise`
#### output
Type: `String`
#### saved
Type: `Float`
This is the Percentage that this lib safed you in a number between `0-1`
### outputType
Type: `String`
can be `image/jpeg` & `image/png` & `image/webp` .
but be aware, we dont support `JPEG => PNG`
## Webpack
if you want to have a webpack loader for it, that uses this package then go to [image-optimizer-webpack-loader](https://github.com/datsteves/image-optimizer-webpack-loader).