D
D
Dmitry2016-02-18 17:33:01
JavaScript
Dmitry, 2016-02-18 17:33:01

How to properly set up gulp-image-resize?

I want to run a lot of pictures through gulp. Those of them that are larger than 2000x2000 pixels should be reduced to this size.
windows 10x64 I
include gulp-image-resize (pre-installed imagemagick and GraphicsMagick )
the task itself

gulp.task('imgresize', function () {
   return gulp.src('src/img/')
      .pipe(imageresize({ 
        width : 100,
        height : 100,
        crop : true,
        upscale : false
      }))
     .pipe(gulp.dest('build/img/'));
});

Initially, the file structure is like this
d39312e2176c4910be043eb97e4a6a17.png
after the task is completed:
2e73658f6fa34412985422486f3004aa.png
I don’t understand why an additional img nesting is created and there are no pictures in the build folder
; moreover, if you write the path, it
gulp.src("src/img/*.*")
gives an error
[16:28:27] Starting 'imgresize'...

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Error: write EPIPE
    at finish (d:\html\working\arplan\node_modules\gulp-image-resize\node_modules\gulp-gm\index.js:40:21)
    at gm.<anonymous> (d:\html\working\arplan\node_modules\gulp-image-resize\node_modules\async\lib\async.js:485:30)
    at gm.emit (events.js:118:17)
    at gm.<anonymous> (d:\html\working\arplan\node_modules\gulp-image-resize\node_modules\gulp-gm\node_modules\gm\lib\getters.js:70:16)
    at Socket.cb (d:\html\working\arplan\node_modules\gulp-image-resize\node_modules\gulp-gm\node_modules\gm\lib\command.js:318:16)
    at Socket.g (events.js:199:16)
    at Socket.emit (events.js:107:17)
    at onwriteError (_stream_writable.js:317:10)
    at onwrite (_stream_writable.js:335:5)
    at WritableState.onwrite (_stream_writable.js:105:5)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Velichko, 2016-02-23
@Zoxon

1. Change return gulp.src('src/img/')to return gulp.src('src/img/**/*.{jpg,png}'))
2. Try using imageMagick, not GraphicsMagick (imageMagick: true)
3. Optionally add optimizations with gulp-changed

var changed = require("gulp-changed");

gulp.task('imgresize', function () {
   return gulp.src('src/img/')
      .pipe(changed("build"))
      .pipe(imageresize({ 
        width : 100,
        height : 100,
        crop : true,
        upscale : false
      }))
     .pipe(gulp.dest('build/img/'));
});

T
timfcsm, 2016-02-18
@timfcsm

you write the path to the folder, not to the pictures...
gulp.src('src/img/**/*.*')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question