This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+89
View File
@@ -0,0 +1,89 @@
'use strict';
const execBuffer = require('exec-buffer');
const isJpg = require('is-jpg');
const mozjpeg = require('mozjpeg');
module.exports = opts => buf => {
opts = Object.assign({}, opts);
if (!Buffer.isBuffer(buf)) {
return Promise.reject(new TypeError('Expected a buffer'));
}
if (!isJpg(buf)) {
return Promise.resolve(buf);
}
const args = ['-outfile', execBuffer.output];
if (typeof opts.quality !== 'undefined') {
args.push('-quality', opts.quality);
}
if (opts.progressive === false) {
args.push('-baseline');
}
if (opts.targa) {
args.push('-targa');
}
if (opts.revert) {
args.push('-revert');
}
if (opts.fastcrush) {
args.push('-fastcrush');
}
if (typeof opts.dcScanOpt !== 'undefined') {
args.push('-dc-scan-opt', opts.dcScanOpt);
}
if (opts.notrellis) {
args.push('-notrellis');
}
if (opts.notrellisDC) {
args.push('-notrellis-dc');
}
if (opts.tune) {
args.push(`-tune-${opts.tune}`);
}
if (opts.noovershoot) {
args.push('-noovershoot');
}
if (opts.arithmetic) {
args.push('-arithmetic');
}
if (opts.dct) {
args.push('-dct', opts.dct);
}
if (typeof opts.quantTable !== 'undefined') {
args.push('-quant-table', opts.quantTable);
}
if (opts.smooth) {
args.push('-smooth', opts.smooth);
}
if (opts.maxmemory) {
args.push('-maxmemory', opts.maxmemory);
}
args.push(execBuffer.input);
return execBuffer({
input: buf,
bin: mozjpeg,
args
}).catch(err => {
err.message = err.stderr || err.message;
throw err;
});
};
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) imagemin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+121
View File
@@ -0,0 +1,121 @@
{
"_args": [
[
{
"raw": "imagemin-mozjpeg@^6.0.0",
"scope": null,
"escapedName": "imagemin-mozjpeg",
"name": "imagemin-mozjpeg",
"rawSpec": "^6.0.0",
"spec": ">=6.0.0 <7.0.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\img-loader"
]
],
"_from": "imagemin-mozjpeg@>=6.0.0 <7.0.0",
"_id": "imagemin-mozjpeg@6.0.0",
"_inCache": true,
"_location": "/imagemin-mozjpeg",
"_nodeVersion": "5.11.0",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/imagemin-mozjpeg-6.0.0.tgz_1461936707653_0.06723950104787946"
},
"_npmUser": {
"name": "kevva",
"email": "kevinmartensson@gmail.com"
},
"_npmVersion": "3.8.8",
"_phantomChildren": {},
"_requested": {
"raw": "imagemin-mozjpeg@^6.0.0",
"scope": null,
"escapedName": "imagemin-mozjpeg",
"name": "imagemin-mozjpeg",
"rawSpec": "^6.0.0",
"spec": ">=6.0.0 <7.0.0",
"type": "range"
},
"_requiredBy": [
"/img-loader"
],
"_resolved": "https://registry.npmjs.org/imagemin-mozjpeg/-/imagemin-mozjpeg-6.0.0.tgz",
"_shasum": "71a32a457aa1b26117a68eeef2d9b190c2e5091e",
"_shrinkwrap": null,
"_spec": "imagemin-mozjpeg@^6.0.0",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\img-loader",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "github.com/kevva"
},
"bugs": {
"url": "https://github.com/imagemin/imagemin-mozjpeg/issues"
},
"dependencies": {
"exec-buffer": "^3.0.0",
"is-jpg": "^1.0.0",
"mozjpeg": "^4.0.0"
},
"description": "mozjpeg imagemin plugin",
"devDependencies": {
"ava": "*",
"is-progressive": "^1.0.1",
"pify": "^2.3.0",
"xo": "*"
},
"directories": {},
"dist": {
"shasum": "71a32a457aa1b26117a68eeef2d9b190c2e5091e",
"tarball": "https://registry.npmjs.org/imagemin-mozjpeg/-/imagemin-mozjpeg-6.0.0.tgz"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"gitHead": "ff54b57ea557c9da24a4a9da9da70509ab135925",
"homepage": "https://github.com/imagemin/imagemin-mozjpeg#readme",
"keywords": [
"compress",
"image",
"imageminplugin",
"img",
"jpeg",
"jpg",
"minify",
"mozjpeg",
"optimize"
],
"license": "MIT",
"maintainers": [
{
"name": "kevva",
"email": "kevinmartensson@gmail.com"
},
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
{
"name": "shinnn",
"email": "snnskwtnb@gmail.com"
}
],
"name": "imagemin-mozjpeg",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/imagemin/imagemin-mozjpeg.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "6.0.0",
"xo": {
"esnext": true
}
}
+147
View File
@@ -0,0 +1,147 @@
# imagemin-mozjpeg [![Build Status](https://travis-ci.org/imagemin/imagemin-mozjpeg.svg?branch=master)](https://travis-ci.org/imagemin/imagemin-mozjpeg) [![Build status](https://ci.appveyor.com/api/projects/status/uuh7yi48erf4ykyo?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/imagemin-mozjpeg)
> mozjpeg imagemin plugin
## Install
```
$ npm install --save imagemin-mozjpeg
```
## Usage
```js
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
imagemin(['images/*.jpg'], 'build/images', {use: [imageminMozjpeg()]}).then(() => {
console.log('Images optimized');
});
```
## API
### imageminMozjpeg([options])(buffer)
Returns a promise for a buffer.
#### options
##### quality
Type: `number`
Compression quality. Min and max are numbers in range 0 (worst) to 100 (perfect).
##### progressive
Type: `boolean`<br>
Default: `true`
`false` creates baseline JPEG file.
##### targa
Type: `boolean`<br>
Default: `false`
Input file is Targa format (usually not needed).
##### revert
Type: `boolean`<br>
Default: `false`
Revert to standard defaults instead of mozjpeg defaults.
##### fastcrush
Type: `boolean`<br>
Default: `false`
Disable progressive scan optimization.
##### dcScanOpt
Type: `number`<br>
Default: `1`
Set DC scan optimization mode.
* `0` One scan for all components
* `1` One scan per component
* `2` Optimize between one scan for all components and one scan for 1st component plus one scan for remaining components
##### notrellis
Type: `boolean`<br>
Default: `false`
Disable [trellis optimization](https://en.wikipedia.org/wiki/Trellis_quantization).
##### notrellisDC
Type: `boolean`<br>
Default: `false`
Disable trellis optimization of DC coefficients.
##### tune
Type: `string`<br>
Default: `hvs-psnr`
Set trellis optimization method. Available methods: `psnr`, `hvs-psnr`, `ssim` and `ms-ssim`
##### noovershoot
Type: `boolean`<br>
Default: `false`
Disable black-on-white deringing via overshoot.
##### arithmetic
Type: `boolean`<br>
Default: `false`
Use [arithmetic coding](https://en.wikipedia.org/wiki/Arithmetic_coding).
##### quantTable
Type: `number`
Use predefined quantization table.
* `0` JPEG Annex K
* `1` Flat
* `2` Custom, tuned for MS-SSIM
* `3` ImageMagick table by N. Robidoux
* `4` Custom, tuned for PSNR-HVS
* `5` Table from paper by Klein, Silverstein and Carney
##### smooth
Type: `number`
Set the strength of smooth dithered input. (1...100)
##### maxmemory
Type: `number`
Set the maximum memory to use in kbytes.
#### buffer
Type: `buffer`
Buffer to optimize.
## License
MIT © [imagemin](https://github.com/imagemin)