GithubHelp home page GithubHelp logo

sindresorhus / gulp-imagemin Goto Github PK

View Code? Open in Web Editor NEW
1.9K 30.0 158.0 219 KB

Minify PNG, JPEG, GIF and SVG images

License: MIT License

JavaScript 100.00%
gulp-plugin imagemin javascript nodejs minify-images compress-images

gulp-imagemin's Introduction

gulp-imagemin

Minify PNG, JPEG, GIF and SVG images with imagemin

Issues with the output should be reported on the imagemin issue tracker.

Install

npm install --save-dev gulp-imagemin

Usage

Basic

import gulp from 'gulp';
import imagemin from 'gulp-imagemin';

export default () => (
	gulp.src('src/images/*')
		.pipe(imagemin())
		.pipe(gulp.dest('dist/images'))
);

Custom plugin options

import imagemin, {gifsicle, mozjpeg, optipng, svgo} from 'gulp-imagemin';

// …
.pipe(imagemin([
	gifsicle({interlaced: true}),
	mozjpeg({quality: 75, progressive: true}),
	optipng({optimizationLevel: 5}),
	svgo({
		plugins: [
			{
				name: 'removeViewBox',
				active: true
			},
			{
				name: 'cleanupIDs',
				active: false
			}
		]
	})
]))
// …

Custom plugin options and custom gulp-imagemin options

import imagemin, {svgo} from 'gulp-imagemin';

// …
.pipe(imagemin([
	svgo({
		plugins: [
			{
				name: 'removeViewBox',
				active: true
			}
		]
	})
], {
	verbose: true
}))
// …

API

Comes bundled with the following optimizers:

  • gifsicleCompress GIF images, lossless
  • mozjpegCompress JPEG images, lossy
  • optipngCompress PNG images, lossless
  • svgoCompress SVG images, lossless

These are bundled for convenience and most users will not need anything else.

imagemin(plugins?, options?)

Unsupported files are ignored.

plugins

Type: Array
Default: [gifsicle(), mozjpeg(), optipng(), svgo()]

Plugins to use. This will completely overwrite all the default plugins. So, if you want to use custom plugins and you need some of defaults too, then you should pass default plugins as well. Note that the default plugins come with good defaults and should be sufficient in most cases. See the individual plugins for supported options.

options

Type: object

verbose

Type: boolean
Default: false

Enabling this will log info on every image passed to gulp-imagemin:

gulp-imagemin: ✔ image1.png (already optimized)
gulp-imagemin: ✔ image2.png (saved 91 B - 0.4%)
silent

Type: boolean
Default: false

Don't log the number of images that have been minified.

You can also enable this from the command-line with the --silent flag if the option is not already specified.

gulp-imagemin's People

Contributors

backflip avatar bfred-it avatar holic avatar kevva avatar larrybotha avatar martijncuppens avatar matthewwithanm avatar ntwb avatar olets avatar phated avatar richienb avatar shinnn avatar shinze avatar shrpne avatar silvenon avatar silverham avatar simplydenis avatar sindresorhus avatar tjbulick avatar ulivz avatar wayneashleyberry avatar wesbos avatar xhmikosr avatar zbennett10 avatar zcei 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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-imagemin's Issues

Misleading description

Please don't say something comes "bundled" with optimizers if I have to then go out and actually download the optimizers myself. "Bundled" should mean that I don't have to add anything else to this to make it work.

Optimization at excluding path

Optimization does not work when excluding way.

gulp.task('default', function () {
    return gulp.src(['src/images/**', '!src/images/sprites/**'])
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngcrush()]
        }))
        .pipe(gulp.dest('dist'));
});
gulp-imagemin: Minified 0 images (saved 0 B - 0%)

Error when using 'gulp.spritesmith': Cannot read property 'contents' of undefined

I use gulp.spritesmith to concatenate my images to single file, and then compress it by gulp-imagemin. Here is my code:

var sprites = gulp.src('./src/**/*.png')
    .pipe(gulpSpritesmith({
        imgName: 'sprites.png',
        cssName: 'sprites.css'
    }));

sprites.img
    .pipe(gulpImagemin({
        progressive: true,
        interlaced: true,
        optimizationLevel: 3,
        svgoPlugins: [{ removeViewBox: false }]
    }))
    .pipe(gulp.dest(outputFolder));

But if there is no image captured by src, imagemin throws exception and fails build process:

D:\Projects\HTML5Client\node_modules\gulp-imagemin\index.js:56
                        var optimizedSize = data.contents.length;
TypeError: Cannot read property 'contents' of undefined
    at Transform.<anonymous> (D:\Projects\HTML5Client\node_modules\gulp-imagemin\index.js:56:28)

I think, the reason is in strange output of the spritesmith module..
Can you fix this issue, please?

Some images are not returned

Looks like some images are not returned by imagemin. I've got this gulp task:

gulp.task('images', function () {
  return gulp.src('app/images/**/*')
    .pipe($.cache($.imagemin({
      optimizationLevel: 3,
      progressive: true,
      interlaced: true
    })))
    .pipe(gulp.dest('dist/images'));
});

And in general it works great. However I've got one file that is devoured by imagemin, here it is: tts-close-button (it's a white cross on alpha background).

When I change contents of this .png (for example add some black stuff) it's being processed as expected.

Invalid glob pattern with jpegtran

So I have my gulpfile configured to compress pngs, jpegs and svg but when I add the jpegtran line, I get this error: "Invalid glob pattern". Any idea what this means? Here's the code I use:

gulp.src(paths.imagesPng, {cwd: paths.src, base: paths.src})
.pipe(imagemin({
use: [pngcrush()]
}))
.pipe(gulp.dest('dist'));

gulp.src(paths.imagesJpeg, {cwd: paths.src, base: paths.src})
.pipe(imagemin({
use: [jpegtran()]
}))
.pipe(gulp.dest('dist'));

gulp.src(paths.imagesSvg, {cwd: paths.src, base: paths.src})
.pipe(imagemin({
use: [svgo()]
}))
.pipe(gulp.dest('dist'));
});

Command failed

I am getting this weird error on my Mac:

[14:59:33] Starting 'imagemin'...
{ [Error: Command failed: ]
  plugin: 'gulp-imagemin:',
  showStack: false,
  name: 'Error',
  message: 'Command failed: ',
  stack: 'Error: Command failed: \n    at ChildProcess.exithandler (child_process.js:647:15)\n    at ChildProcess.emit (events.js:98:17)\n    at maybeClose (child_process.js:755:16)\n    at Socket.<anonymous> (child_process.js:968:11)\n    at Socket.emit (events.js:95:17)\n    at Pipe.close (net.js:465:12)' }

the gulp code is:

gulp.task('imagemin', ['clean:img'], function() {
    return gulp.src(paths.uncompressedImages)
        .pipe(imagemin({
            optimizationLevel: 4,
            progressive:       true,
            interlaced:        true
        }))
        .on('error', console.error)
        .pipe(gulp.dest(paths.img))
})

Duplexer issue in Linux

I'm wanting to use imagemin in Linux [Fedora 20]. I'm mentioning Linux, because I know imagemin works really well in windows, and that appears to be the only difference.
Whats up with that?

module.js:340
    throw err;
          ^
Error: Cannot find module 'duplexer'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/whead/Dropbox/shared/repos/rtpa/extension/workbench/node_modules/gulp-imagemin/node_modules/image-min/node_modules/optipng-bin/node_modules/bin-wrapper/node_modules/download/node_modules/decompress/node_modules/stream-combiner/index.js:1:78)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Getting numerous errors on `npm install --save-dev gulp-imagemin`

I'm behind a corporate proxy and have set it up and set strict-ssl to false and the ca to "" but it still doesn't seem to be working. I don't have any issues installing other packages atm.

Errors:

> [email protected] postinstall C:\web\www\gxl-build\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\imagemin-gifs
icle\node_modules\gifsicle
> node index.js

\
? Installation of gifsicle failed

Try installing the binary manually by visiting http://www.lcdf.org/gifsicle/
and choose the desired binary for your platform.

Then try reinstalling this module again.
|


> [email protected] postinstall C:\web\www\gxl-build\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\imagemin-
pngquant\node_modules\pngquant-bin
> node index.js

? pre-build test failed, compiling from source...
libpng-dev is installed

[Error: CERT_UNTRUSTED]
\


> [email protected] postinstall C:\web\www\gxl-build\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\imagemin-o
ptipng\node_modules\optipng-bin
> node index.js

? pre-build test failed, compiling from source...
? Error: Command failed: '.' is not recognized as an internal or external command,
operable program or batch file.




> [email protected] postinstall C:\web\www\gxl-build\node_modules\gulp-imagemin\node_modules\imagemin\node_modules\imagemin-
jpegtran\node_modules\jpegtran-bin
> node index.js

? CERT_UNTRUSTED
? CERT_UNTRUSTED
[email protected] node_modules\gulp-imagemin
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], multi
[email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected],
 [email protected], [email protected], [email protected], [email protected], [email protected], imagemin-jpeg
[email protected])

Selective load of imagemin- modules

It would be nice to have a way to specify the imagemin methods loaded. Why ?

Now by default it load them all in gulp-imagemin/index.js.

So even though I'm not using optipng , I'm still hit by this bug:
Error: Command failed: ** Error: Lossy operations are not currently supported.
It's basically because an older version of optipng is installed.
I can't change the config of the build server (CircleCI).

See gruntjs/grunt-contrib-imagemin#187 for the grunt equivalent.

gulp-imagemin is missing some nested folders.

I got this old project, with lots of images scattered under some sub folders, like:

  • js
    • styles
      • images
        • a.jpg
    • b.jpg
  • images
    • c.png
    • index
      • d.jpg

So, I try this:

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

gulp.task('default', function () {
    return gulp.src('src/**/*.{jpg,png,gif}')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngcrush()]
        }))
        .pipe(gulp.dest('dist'));
});

After the task was done, I checked the files count and found that some folders(not empty) with images were left out.

Breaking in Ubuntu?

Latest version of gulp-imagemin won't work in Ubuntu.
Ubuntu already includes a version of optipng, and it tries to use that one, since it's an old version it fails with Error: Lossy operations are not currently supported.

Not sure how to solve. I'm using gulp-image and it works for png's. They appear to require optipng-bin directly.

Maybe this is an issue related to imagemin itself? If imagemin requires the version of imagemin-optipng that forces it to use v0.7.4 of optipng then it should work. It appears the latest version removed that. Relevant commit

Can't update Ubuntu because it's on CircleCI.

I found these related issues:
gruntjs/grunt-contrib-imagemin#180
gruntjs/grunt-contrib-imagemin#210

Use streams

Since image-min only supports input/output file, file.path is supplied as input and a temp dir as output, afterwards the tempfile is read in.

Would be so much nicer to use streams.

Depends on imagemin/imagemin#6

Error after npm update: Cannot call method 'replace' of undefined

Hi,

I just made a 'npm update' and I'm having this error message when I run gulp:

G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\node_modules\image-min\nod
e_modules\win-spawn\index.js:7
    command = command.replace(/\//g, '\\');
                      ^
TypeError: Cannot call method 'replace' of undefined
    at spawn (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\node_modules
\image-min\node_modules\win-spawn\index.js:7:23)
    at Imagemin._optimizePng (G:\xampp\htdocs\medula\dmj\node_modules\gulp-image
min\node_modules\image-min\index.js:109:12)
    at Imagemin.optimize (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\
node_modules\image-min\index.js:29:19)
    at module.exports (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\nod
e_modules\image-min\index.js:123:21)
    at Transform._transform (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagem
in\index.js:35:10)
    at Transform._read (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\no
de_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10
)
    at Transform._write (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\n
ode_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:1
2)
    at doWrite (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\node_modul
es\through2\node_modules\readable-stream\lib\_stream_writable.js:238:10)
    at writeOrBuffer (G:\xampp\htdocs\medula\dmj\node_modules\gulp-imagemin\node
_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:228:5)
    at Transform.Writable.write (G:\xampp\htdocs\medula\dmj\node_modules\gulp-im
agemin\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.j
s:195:11)

My task

// Images
gulp.task('images', function() {
    return gulp.src('src/imgs/**/*')
        .pipe(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true }))
        .pipe(gulp.dest('build/dev/imgs'))
        .pipe(gulp.dest('build/production/imgs'));
});

Compress source images

I'm using gulp-imagemin to compress images in app/images and output to dist/images.

However, I'd also like these source images in app/images to be compressed, so I can completely ignore the dist/images folder in .gitignore and be sure the images in both locations are compressed and identical.

I don't see an easy way of achieving this? Specifying two dest paths doesn't seem to do the trick.

total saved bytes

It would be nice if there was an option to show how many bytes were saved in total.
As a workaround I put .pipe(size()) at the beginning and end of my task.

spawn ENOENT

version ^0.6.0

It seems imagemin have some problems on its dependencies.

No pngquant in imagemin

Imagemin contains option pngquant, but it's not in package, thus optimalization isn't done via pngquant (huge file savings).

Please, add it to the package (it was removed for no obvious reason also from grunt-contrib-imagemin)

Add `use` option

Or something like that which exposes imagemin and lets the users add their own plugins. Either through a use option or using arguments like you do in gulp-rework.

Option optimizationLevel ignored

Tried different optimizationLevels from 0 to 7 on many images and the output is always exactly the same on pngs and jpgs. Is this correct?
gulp-imagemin v.0.6.1

Error: File.contents can only be a Buffer, a Stream, or null.

$ gulp images
[gulp] Using gulpfile ~/www/gitblog/gulpfile.js
[gulp] Starting 'images'...
[gulp] gulp-imagemin:  sample.jpg (saved 58.8 kB)

Error: File.contents can only be a Buffer, a Stream, or null.
    at File.Object.defineProperty.set (/Users/alexandruvladutu/www/gitblog/node_modules/gulp/node_modules/vinyl-fs/node_modules/vinyl/index.js:110:13)
    at Transform.<anonymous> (/Users/alexandruvladutu/www/gitblog/node_modules/gulp-imagemin/index.js:43:19)
    at ConcatStream.<anonymous> (/Users/alexandruvladutu/www/gitblog/node_modules/gulp-imagemin/node_modules/concat-stream/index.js:32:43)
    at ConcatStream.EventEmitter.emit (events.js:117:20)
    at finishMaybe (/Users/alexandruvladutu/www/gitblog/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:455:14)
    at endWritable (/Users/alexandruvladutu/www/gitblog/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:464:3)
    at ConcatStream.Writable.end (/Users/alexandruvladutu/www/gitblog/node_modules/gulp-imagemin/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:431:5)
    at DuplexWrapper.onend (_stream_readable.js:483:10)
    at DuplexWrapper.g (events.js:180:16)
    at DuplexWrapper.EventEmitter.emit (events.js:117:20)

Code:

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

var paths = {
  dev: {
    scripts: 'public/dev/js/*.js',
    stylesheets: 'public/dev/css/*.css',
    images: ['public/dev/imgs/*.jpeg', 'public/dev/imgs/*.jpg', 'public/dev/imgs/*.png','public/dev/imgs/*.gif']
  },
  out: {
    scripts: 'public/assets/js',
    stylesheets: 'public/assets/css',
    images: 'public/assets/imgs'
  }
};

// Copy all static images
gulp.task('images', function() {
 return gulp.src(paths.dev.images)
    // Pass in options to the task
    .pipe(imagemin({optimizationLevel: 5}))
    .pipe(gulp.dest(paths.out.images));
});

The file in question is 57 Kb, very small.

Thoughts?

Imagemin losing files from stream.

This is a really weird bug. I've tried to collect as much diagnostic information as possible to help diagnose it. I actually browsed the source code myself and didn't see anything that looked like a possible culprit.

When I pipe from src -> imagemin -> dest:

  1. imagemin correctly runs against all files
  2. Returns only a single optimized file (and nothing else) to the stream.
  3. That single file is then correctly saved to dest.

Notes:

  • When I remove the pipe through imagemin it works fine.
  • When I pipe src -> debug -> imagemin -> dest, the first debug shows all files, the last shows only the one which gets saved.
  • There is no indication of a failure state in imagemin.

Here's the relevant task trimmed to minimally reproduce the error: http://pastebin.com/YfBB3XMb

The require statements aren't listed but are all correct. The task is run with gulp images

Here's a representative snippet of the output with src -> imagemin -> debug -> dest:
http://pastebin.com/9uJFQEiq

Happy to provide any other information that might be useful.

optipng vs pngquant

Hey, just tried using gulp-imagemin, but found some issues with usage.

  1. Can't use pngquant, even though it's a dependency for imagemin.
  2. When using pngquant (installing it on your own, which is a little redundant considering the previous point) you are forced to go through optipng, which is VERY slow, and doesn't necessarily translate to size reduction.

So, unless I'm missing something, shouldn't it be a flag between lossy:lossless which translates to using pngquant:optipng ?

Error with imagemin

Get following error:

        throw new TypeError('First argument needs to be a number, ' +
              ^
TypeError: First argument needs to be a number, array or string.
    at new Buffer (buffer.js:188:15)
    at /Applications/MAMP/htdocs/Work/Adoptive/yale/YSMWebsites/Template 3.0/SDL Tridion/CD/DD4T/Website/static/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-svgo/index.js:24:29
    at /Applications/MAMP/htdocs/Work/Adoptive/yale/YSMWebsites/Template 3.0/SDL Tridion/CD/DD4T/Website/static/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-svgo/node_modules/svgo/lib/svgo.js:31:13
...

with the following gulp call:

gulp.task('sprite', function () {
    return gulp.src(src_dir + '/images/*.svg')
        .pipe(svgSprite())
        .pipe(gulp.dest(src_dir + '/images/sprite'))
        .pipe(gulp.dest(dest_dir + '/images/sprite'));
});


gulp.task('images', ['sprite'], function () {
    return gulp.src(src_dir + '/images/**/*')
        .pipe($.cache($.imagemin({
            optimizationLevel: 1,
            progressive: true,
            interlaced: true
        })))
        .pipe(gulp.dest(dest_dir + '/images'))
        .pipe($.size());
});

Included 'sprite' because I found it to be relevant.

NPM package install fail

your module fails with the most current:

npm ERR! node -v v0.10.31
npm ERR! npm -v 2.0.0-beta.0
npm ERR! EEXIST, mkdir '/nodejs/GAOWL/node_modules/gulp-imagemin/node_modules/im
agemin/node_modules/imagemin-optipng/node_modules/optipng-bin/node_modules/bin-w
rapper/node_modules/download/node_modules/fs-extra/lib'
File exists: /nodejs/GAOWL/node_modules/gulp-imagemin/node_modules/imagemin/node
_modules/imagemin-optipng/node_modules/optipng-bin/node_modules/bin-wrapper/node
_modules/download/node_modules/fs-extra/lib
Move it away, and try again.

File path length - unable to delete folder on Windows

When working with gulp-imagemin on a Windows machine, the setup of gulp results in a file path that is too long for Windows to be able to delete. This makes it difficult to delete any parent folder containing gulp-imagemin.

Similar problem seen here and now fixed: gulpjs/gulp#630

Can anything be done to fix this?

example

Images are not saved when `gulp-if` is used

Images are optimized and saved properly when using this task:

gulp.task('img.app', ['clean.img.app'], function () {
    return gulp
        .src('app/styles/**/img/*.*')
        .pipe(imagemin())
        .pipe(gulp.dest('public/app/img'));
});

But when I add gulp-if like this:

gulp.task('img.app', ['clean.img.app'], function () {
    return gulp
        .src('app/styles/**/img/*.*')
        .pipe(gulpif(true, imagemin()))
        .pipe(gulp.dest('public/app/img'));
});

...images are optimized but not saved.
I think that it's a gulp-imagemin bug, because in all other cases gulp-if works properly.

Malware

I just installed this package on my windows machine and was notified of malware.

Detected Item: PWS:Win32/Lineage.gen!C.dam
Alert Level: Severe
File: gulp-imagemin\node_modules\image-min\node_modules\imagemin-pngquant\node_modules\pngquant-bin\vendor\pngquant.exe

Obviously its in a sub-sub-sub package, but something to be aware of.

Property 'optimizer' of object #<Imagemin> is not a function

/Users/<redacted>/node_modules/gulp-imagemin/node_modules/image-min/imagemin.js:59
    var optimizer = this.optimizer(this.src, this.dest, cb);
                         ^
TypeError: Property 'optimizer' of object #<Imagemin> is not a function
    at Imagemin.optimize (/Users/contra/Projects/sportsgamet/node_modules/gulp-imagemin/node_modules/image-min/imagemin.js:59:26)
    at module.exports (/Users/contra/Projects/sportsgamet/node_modules/gulp-imagemin/node_modules/image-min/imagemin.js:173:21)
    at /Users/contra/Projects/sportsgamet/node_modules/gulp-imagemin/index.js:25:5
    at Object.oncomplete (fs.js:107:15)

Task just looks like this

gulp.task 'images', ->
  return gulp.src('./client/img/**/*')
    .pipe(imagemin())
    .pipe(gulp.dest('./public/img'))

gulp-imagemin 0.1.1

gulp-imagemin install fails on windows 8

> [email protected] postinstall path\node_modules\gulp-imagemin\node_modules\image-min\node_modules\pngquant-bin
> node index.js

✓ pre-build test passed successfully

> [email protected] postinstall path\node_modules\gulp-imagemin\node_modules\image-min\node_modules\gifsicle
> node index.js

✓ pre-build test passed successfully

> [email protected] postinstall path\node_modules\gulp-imagemin\node_modules\image-min\node_modules\jpegtran-bin
> node index.js

✗ building is not supported on win32

Same issue with grunt-contrib-imagemin
gruntjs/grunt-contrib-imagemin#109

SHA1 Hash changes when file already optimized

I noticed that all my image files being passed to my imagemin task where being changed, even if they didn't need to be optimized. Specifically, the SHA1 hash of the file was different, and the modified time was updated.

This only happens when the source and destination for the file is the same. It creates a bit of havoc in my git repo, since I can't get an accurate picture of what was modified.

Here's a sample gulpfile:

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

gulp.task('default', function () {
    return gulp.src('images/src/*.png')
            .pipe(imagemin({ ext: "png", pngquant: true}))
            .pipe(gulp.dest('images/src'));
});

I'm using imagemin 0.3.0 and gulp 3.6.0.

set verbosity

It would be great to have an option to disable the per-file logging, it can get quite out of hand if you have a lot of images.

Dependencies are broken

The cache-file plugin by @kevva was apparently (prematurely?) removed from NPM and the GitHub repository was deleted. This is causing npm to fail installing on all projects which depend on gulp-imagemin, because one of the gulp-imagemin dependencies used cache-file.

I'm not sure which dependency it is, but thought that you may be interested in hearing about this issue. I think that the solution may be to simply update image-min?

It might make sense to make use of peerDependencies so that projects like mine can provide their own recommendation regarding which version of image-min to use?

installation fails: optional dep failed

As stated:

npm install gulp-imagemin

throws:

And the installation fails. What's going on?

Tried to 

npm cache clean

with no luck

Favicon support?

Just wondering ... since there is no imagemin for favicons, favicon support might be out of question.

Missing dependency ?

With the given sample it seems necessary to install imagemin-pngcrush before it can work.

Make it more configurable

Right now we support plugins, but there's no way to disable the built-in plugins.

Would be nice if everything was a plugin.

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

gulp.task('default', function () {
    return gulp.src('src/images/*')
        .pipe(pngcrush())
        .pipe(gulp.dest('dist'));
});

gulp-imagemin would still exist as a handy bundle for the common configuration, but it would be possible to use any plugin separately.

@kevva Would it be possible to add support to the imagemin plugins to be used directly in the stream? That would be super nice and much more aligned with what gulp users are used to.

Error: spawn EMFILE

What is this error?

child_process.js:935
    throw errnoException(process._errno, 'spawn');
          ^
Error: spawn EMFILE
    at errnoException (child_process.js:988:11)
    at ChildProcess.spawn (child_process.js:935:11)
    at exports.spawn (child_process.js:723:9)
    at Imagemin._optimizePng (/Volumes/DEVEAD/WAMP/www/moodle/theme/numeramento/node_modules/gulp-imagemin/node_modules/image-min/imagemin.js:151:12)
    at Imagemin.optimize (/Volumes/DEVEAD/WAMP/www/moodle/theme/numeramento/node_modules/gulp-imagemin/node_modules/image-min/imagemin.js:63:26)
    at module.exports (/Volumes/DEVEAD/WAMP/www/moodle/theme/numeramento/node_modules/gulp-imagemin/node_modules/image-min/imagemin.js:189:21)
    at /Volumes/DEVEAD/WAMP/www/moodle/theme/numeramento/node_modules/gulp-imagemin/index.js:38:5
    at Object.oncomplete (fs.js:107:15)

Optimise changed images only

Just wondering if it's possible to optimise only modified images like Grunts contrib-imagemin? Saves optimising the same images each time, handy when using with watch so only changes/new images will be optimised.

Cheers!

Gulp task never ends

Hi,

Not sure what the problem is here but when using gulp-imagemin, the gulp task never ends and leaves the process hanging (manual ctrl+c required).

For example:

gulp.task('build-images', function() {
  return gulp.src(paths.images)
    .pipe(imagemin({pngquant:true}))
    .pipe(gulp.dest(paths.build + "images/"));
});

Runnig gulp build-images reports:

[gulp] Running 'build-images'...
[gulp] gulp-imagemin: ✔ image1.png (saved 176.83 kB)
[gulp] gulp-imagemin: ✔ image2.png (saved 2.45 kB)
[gulp] Finished 'build-images' in 190 ms

Gulp reports as if the task has ended, but the process never ends.
Using gulp-imagemin v0.2.0 and gulp 3.5.6

Error That Fixes by Restarting

I get the following error sometimes that is fixed by restarting my Macbook Air:

[19:42:41] Using gulpfile ~/apps/sowhatsbitcoin.com/gulpfile.js
[19:42:41] Starting 'crush'...

events.js:72 
    throw er; // Unhandled 'error' event
        ^
Error: Command failed: 
    at ChildProcess.exithandler (child_process.js:647:15)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:755:16)
    at Socket.<anonymous> (child_process.js:968:11)
    at Socket.emit (events.js:95:17)
    at Pipe.close (net.js:465:12)

Here is my task:

gulp.task('crush', function () {
    return gulp.src('./images/*')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngcrush()],
            optimizationLevel: 7
        }))
        .pipe(gulp.dest('./images'));
});

Waiting till imagemin is done

Hi,

I'm using gulp-imagemin with RunSequence: https://www.npmjs.org/package/run-sequence .

For some reason it:

  • finds that imagemin is done almost instantly
  • but imagemin continuous for a while (seems to run in parallel)

I suspect gulp-imagemin is calling the callback too soon. The run-sequence mentions that is listens to the 'task_stop' event, but I could find no info on it.

Thanks for helping me out on this.

Error when running on testing server (Ubuntu)

Here's the output I'm getting from imagemin:

{ [Error: spawn EACCES]
  plugin: 'gulp-imagemin:',
  showStack: undefined,
  name: 'Error',
  message: 'spawn EACCES',
  fileName: undefined,
  lineNumber: undefined,
  stack: 'Error: spawn EACCES\n    at errnoException (child_process.js:1001:11)\n    at Process.ChildProcess._handle.onexit (child_process.js:792:34)' }

xxx/node_modules/gulp-imagemin/index.js:46
            var saved = file.contents.length - data.contents.length;
                                                   ^
TypeError: Cannot read property 'contents' of undefined
    at Transform.<anonymous> (xxx/node_modules/gulp-imagemin/index.js:46:43)
    at xxx/node_modules/gulp-imagemin/node_modules/image-min/index.js:77:24
    at next (xxx/node_modules/gulp-imagemin/node_modules/image-min/node_modules/ware/lib/index.js:48:42)
    at next (xxx/node_modules/gulp-imagemin/node_modules/image-min/node_modules/ware/lib/index.js:50:52)
    at xxx/node_modules/gulp-imagemin/node_modules/image-min/node_modules/imagemin-optipng/index.js:41:28
    at exithandler (child_process.js:644:7)
    at ChildProcess.errorhandler (child_process.js:660:5)
    at ChildProcess.emit (events.js:95:17)
    at Process.ChildProcess._handle.onexit (child_process.js:808:12)

I don't know a lot about how node does things, so sadly I know not how to debug this.

mini images bug

code:

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');//图片压缩

gulp.task('miniimg', function () {
    gulp.src('./dev/images/index1.jpg')
        .pipe(imagemin())
        .pipe(gulp.dest('./dist/images'));
});

// 默认任务
gulp.task('default', function() {
    gulp.run('miniimg');
});

error is here:


events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)


what's wrong ?

imagemin-gifsicle faliing to install

When i am trying to install imagemin through gulp i am having the below issue:

[email protected] postinstall /usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-optipng/node_modules/optipng-bin
node index.js

✔︎ pre-build test passed successfully!

[email protected] postinstall /usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-pngquant/node_modules/pngquant-bin
node index.js

⚠ pre-build test failed, compiling from source...
✔︎ pngquant built successfully!

[email protected] postinstall /usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle
node index.js

⚠ pre-build test failed, compiling from source...

stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: invalid tar file
at Extract.Parse._startEntry (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/lib/parse.js:145:13)
at Extract.Parse._process (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/lib/parse.js:127:12)
at BlockStream. (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/lib/parse.js:47:8)
at BlockStream.emit (events.js:95:17)
at BlockStream._emitChunk (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/node_modules/block-stream/block-stream.js:145:10)
at BlockStream.resume (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/node_modules/block-stream/block-stream.js:58:15)
at Extract.Reader.resume (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/node_modules/fstream/lib/reader.js:255:34)
at DirWriter. (/usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/lib/extract.js:57:8)
at DirWriter.emit (events.js:92:17)
at /usr/local/tools/bamboo/agent01/xml-data/build-dir/ESERVII-WOCIU-JOB1/workorder/webapp/ui/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/node_modules/bin-build/node_modules/download/node_modules/decompress/node_modules/tar/node_modules/fstream/lib/dir-writer.js:39:8
npm WARN optional dep failed, continuing [email protected]
[email protected] node_modules/gulp-imagemin
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

using npm 1.4.21

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.