Galerie und tage
This commit is contained in:
100
node_modules/imagemin-jpegtran/index.js
generated
vendored
100
node_modules/imagemin-jpegtran/index.js
generated
vendored
@@ -1,39 +1,83 @@
|
||||
'use strict';
|
||||
const execBuffer = require('exec-buffer');
|
||||
const isJpg = require('is-jpg');
|
||||
const jpegtran = require('jpegtran-bin');
|
||||
|
||||
module.exports = opts => buf => {
|
||||
opts = Object.assign({}, opts);
|
||||
var spawn = require('child_process').spawn;
|
||||
var isJpg = require('is-jpg');
|
||||
var jpegtran = require('jpegtran-bin');
|
||||
var through = require('through2');
|
||||
|
||||
if (!Buffer.isBuffer(buf)) {
|
||||
return Promise.reject(new TypeError('Expected a buffer'));
|
||||
}
|
||||
module.exports = function (opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (!isJpg(buf)) {
|
||||
return Promise.resolve(buf);
|
||||
}
|
||||
return through.ctor({objectMode: true}, function (file, enc, cb) {
|
||||
if (file.isNull()) {
|
||||
cb(null, file);
|
||||
return;
|
||||
}
|
||||
|
||||
const args = ['-copy', 'none'];
|
||||
if (file.isStream()) {
|
||||
cb(new Error('Streaming is not supported'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.progressive) {
|
||||
args.push('-progressive');
|
||||
}
|
||||
if (!isJpg(file.contents)) {
|
||||
cb(null, file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.arithmetic) {
|
||||
args.push('-arithmetic');
|
||||
} else {
|
||||
args.push('-optimize');
|
||||
}
|
||||
var args = ['-copy', 'none', '-optimize'];
|
||||
var ret = [];
|
||||
var len = 0;
|
||||
var err = '';
|
||||
|
||||
args.push('-outfile', execBuffer.output, execBuffer.input);
|
||||
if (opts.progressive) {
|
||||
args.push('-progressive');
|
||||
}
|
||||
|
||||
return execBuffer({
|
||||
input: buf,
|
||||
bin: jpegtran,
|
||||
args
|
||||
}).catch(error => {
|
||||
error.message = error.stderr || error.message;
|
||||
throw error;
|
||||
if (opts.arithmetic) {
|
||||
args.push('-arithmetic');
|
||||
}
|
||||
|
||||
var cp = spawn(jpegtran, args);
|
||||
|
||||
cp.stderr.setEncoding('utf8');
|
||||
cp.stderr.on('data', function (data) {
|
||||
err += data;
|
||||
});
|
||||
|
||||
cp.stdout.on('data', function (data) {
|
||||
ret.push(data);
|
||||
len += data.length;
|
||||
});
|
||||
|
||||
cp.on('error', function (err) {
|
||||
err.fileName = file.path;
|
||||
cb(err);
|
||||
return;
|
||||
});
|
||||
|
||||
cp.on('close', function () {
|
||||
var contents = Buffer.concat(ret, len);
|
||||
|
||||
if (err && (err.code !== 'EPIPE' || !isJpg(contents))) {
|
||||
err = typeof err === 'string' ? new Error(err) : err;
|
||||
err.fileName = file.path;
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (len < file.contents.length) {
|
||||
file.contents = contents;
|
||||
}
|
||||
|
||||
cb(null, file);
|
||||
});
|
||||
|
||||
cp.stdin.on('error', function (stdinErr) {
|
||||
if (!err) {
|
||||
err = stdinErr;
|
||||
}
|
||||
});
|
||||
|
||||
cp.stdin.end(file.contents);
|
||||
});
|
||||
};
|
||||
|
||||
38
node_modules/imagemin-jpegtran/package.json
generated
vendored
38
node_modules/imagemin-jpegtran/package.json
generated
vendored
@@ -1,36 +1,26 @@
|
||||
{
|
||||
"name": "imagemin-jpegtran",
|
||||
"version": "6.0.0",
|
||||
"version": "4.3.2",
|
||||
"description": "jpegtran imagemin plugin",
|
||||
"license": "MIT",
|
||||
"repository": "imagemin/imagemin-jpegtran",
|
||||
"author": {
|
||||
"name": "Kevin Mårtensson",
|
||||
"email": "kevinmartensson@gmail.com",
|
||||
"url": "github.com/kevva"
|
||||
"url": "https://github.com/kevva"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
{
|
||||
"name": "Shinnosuke Watanabe",
|
||||
"url": "github.com/shinnn"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
"test": "xo && node test/test.js"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"compress",
|
||||
"gulpplugin",
|
||||
"image",
|
||||
"imageminplugin",
|
||||
"img",
|
||||
@@ -41,17 +31,15 @@
|
||||
"optimize"
|
||||
],
|
||||
"dependencies": {
|
||||
"exec-buffer": "^3.0.0",
|
||||
"is-jpg": "^2.0.0",
|
||||
"jpegtran-bin": "^4.0.0"
|
||||
"is-jpg": "^1.0.0",
|
||||
"jpegtran-bin": "^3.0.0",
|
||||
"through2": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"is-progressive": "^3.0.0",
|
||||
"pify": "^4.0.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"xo": {
|
||||
"esnext": true
|
||||
"ava": "^0.0.4",
|
||||
"buffer-equal": "^0.0.1",
|
||||
"vinyl-file": "^1.1.0",
|
||||
"vinyl-smallest-jpeg": "^1.0.0",
|
||||
"xo": "^0.10.1"
|
||||
}
|
||||
}
|
||||
|
||||
41
node_modules/imagemin-jpegtran/readme.md
generated
vendored
41
node_modules/imagemin-jpegtran/readme.md
generated
vendored
@@ -13,43 +13,48 @@ $ npm install --save imagemin-jpegtran
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const imagemin = require('imagemin');
|
||||
const Imagemin = require('imagemin');
|
||||
const imageminJpegtran = require('imagemin-jpegtran');
|
||||
|
||||
imagemin(['images/*.jpg'], 'build/images', {use: [imageminJpegtran()]}).then(() => {
|
||||
console.log('Images optimized');
|
||||
new Imagemin()
|
||||
.src('images/*.jpg')
|
||||
.dest('build/images')
|
||||
.use(imageminJpegtran({progressive: true}))
|
||||
.run();
|
||||
```
|
||||
|
||||
You can also use this plugin with [gulp](http://gulpjs.com):
|
||||
|
||||
```js
|
||||
const gulp = require('gulp');
|
||||
const imageminJpegtran = require('imagemin-jpegtran');
|
||||
|
||||
gulp.task('default', () => {
|
||||
return gulp.src('images/*.jpg')
|
||||
.pipe(imageminJpegtran({progressive: true})())
|
||||
.pipe(gulp.dest('build/images'));
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### imageminJpegtran([options])(buffer)
|
||||
### imageminJpegtran(options)
|
||||
|
||||
Returns a promise for a buffer.
|
||||
#### options.progressive
|
||||
|
||||
#### options
|
||||
|
||||
##### progressive
|
||||
|
||||
Type: `boolean`<br>
|
||||
Type: `boolean`
|
||||
Default: `false`
|
||||
|
||||
Lossless conversion to progressive.
|
||||
|
||||
##### arithmetic
|
||||
#### options.arithmetic
|
||||
|
||||
Type: `boolean`<br>
|
||||
Type: `boolean`
|
||||
Default: `false`
|
||||
|
||||
Use [arithmetic coding](http://en.wikipedia.org/wiki/Arithmetic_coding).
|
||||
|
||||
#### buffer
|
||||
|
||||
Type: `buffer`
|
||||
|
||||
Buffer to optimize.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user