Giter VIP home page Giter VIP logo

imagemin-zopfli's Introduction

imagemin

Minify images seamlessly

Install

npm install imagemin

Usage

import imagemin from 'imagemin';
import imageminJpegtran from 'imagemin-jpegtran';
import imageminPngquant from 'imagemin-pngquant';

const files = await imagemin(['images/*.{jpg,png}'], {
	destination: 'build/images',
	plugins: [
		imageminJpegtran(),
		imageminPngquant({
			quality: [0.6, 0.8]
		})
	]
});

console.log(files);
//=> [{data: <Uint8Array 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]

API

imagemin(input, options?)

Returns Promise<object[]> in the format {data: Uint8Array, sourcePath: string, destinationPath: string}.

input

Type: string[]

File paths or glob patterns.

options

Type: object

destination

Type: string

Set the destination folder to where your files will be written. If no destination is specified, no files will be written.

plugins

Type: Array

The plugins to use.

glob

Type: boolean
Default: true

Enable globbing when matching file paths.

imagemin.buffer(data, options?)

Returns Promise<Uint8Array>.

data

Type: Uint8Array

The image data to optimize.

options

Type: object

plugins

Type: Array

Plugins to use.

Related

imagemin-zopfli's People

Contributors

1000ch avatar kevva avatar shinnn avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

imagemin-zopfli's Issues

Is it compatible with gulp-imagemin?

Have this error:

[00:26:50] TypeError: dest.on is not a function
at DestroyableTransform.Readable.pipe (D:\Projects\boxy\node_modules\vinyl-fs\node_modules\readable-stream\lib_stream_readable.js:516:8)
at Gulp. (D:\Projects\boxy\gulpfile.js:369:6)
at module.exports (D:\Projects\boxy\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (D:\Projects\boxy\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (D:\Projects\boxy\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (D:\Projects\boxy\node_modules\orchestrator\index.js:134:8)
at C:\Users\Ihor\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (node.js:376:9)
at process._tickCallback (node.js:407:11)
at Function.Module.runMain (module.js:449:11)

has no method 'on' error

I tried imagemin-zopfli with gulp but I got a error.

error

TypeError: Object function (file, imagemin, cb) {
    if (!isPng(file.contents)) {
        cb();
        return;
    }

    var exec = new ExecBuffer();
    var args = ['-y'];

    if (opts.more) {
        args.push('-m');
    }

    if (opts['8bit']) {
        args.push('--lossy_8bit');
    }

    exec
        .use(zopfli, args.concat([exec.src(), exec.dest()]))
        .run(file.contents, function (err, buf) {
            if (err) {
                cb(err);
                return;
            }

            file.contents = buf;
            cb();
        });
    } has no method 'on'
at DuplexWrapper.Readable.pipe (/Users/Moriken/Sites/imagemin/node_modules/gulp/node_modules/vinyl-fs/node_modules/duplexer2/node_modules/readable-stream/lib/_stream_readable.js:527:8)
at Gulp.<anonymous> (/Users/Moriken/Sites/imagemin/gulpfile.js:6:10)
at module.exports (/Users/Moriken/Sites/imagemin/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/Moriken/Sites/imagemin/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/Moriken/Sites/imagemin/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/Moriken/Sites/imagemin/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at /usr/local/lib/node_modules/gulp/bin/gulp.js:121:20
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)

gulpfile.js

var gulp = require('gulp');
var zopfli = require('imagemin-zopfli');

gulp.task('default', function () {
    return gulp.src('images/*.png')
        .pipe(zopfli())
        .pipe(gulp.dest('build/images'));
});

package.json

{
  "name": "imagemin",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "gulp": "^3.8.8",
    "imagemin-zopfli": "^1.0.0"
  }
}

Feature request: lossy_transparent option

Not sure what the procedure is, so feel free to close if this isn't the right process.

Would it be possible to add lossy_transparent to the options available to pass on to zopfli (pass on as --lossy_transparent)? Or would it be better to just submit a pull request with the option?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.