Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup files.scale object in Gulp task? #2

Closed
kimfucious opened this issue May 17, 2018 · 2 comments

Comments

@kimfucious
Copy link

commented May 17, 2018

Hi there,

I was liking the looks of gulp-scale-images over gulp-image-resize, as it doesn't require gm and it seems well maintained.

Sorry for the potentially dumb question, but if all I want to do is run through a directory full of image files to produce a bunch of thumbnails, without using through2 or flat-map, how would I setup the files.scale object?

Here's my gulp task:

gulp.task("thumbs", () => {
  return gulp
    .src(paths.img_thumbs_src)
    .pipe(scaleImages())
    .pipe(gulp.dest(paths.img_thumbs_dist))
    .on("error", gutil.log);
});

When I run it I get:

Error: file.scale must be an object

I'm sure there's an easy answer to this, but I just couldn't glean this from the docs.

Thanks,

Kim

@derhuerst

This comment has been minimized.

Copy link
Owner

commented May 17, 2018

Sorry for the potentially dumb question, but if all I want to do is run through a directory full of image files to produce a bunch of thumbnails, without using through2 or flat-map, how would I setup the files.scale object?

You would have to use through2 or flat-map in your case. gulp-scale-images does not decide for you how to scale the images; You may use any logic to generate the file.scale instructions.

The simplest thumbnail generation would probably look like this:

const gulp = require('gulp')
const through2 = require('through2')
const scaleImages = require('gulp-scale-images')

const thumbnail = (file, cb) => {
	file.scale = {maxWidth: 200}
	cb(null, file)
}

gulp.src('path/to/pictures/*.{jpeg,jpg,png}')
.pipe(through2.obj(thumbnail))
.pipe(scaleImages())
.pipe(gulp.dest(…))
@derhuerst

This comment has been minimized.

Copy link
Owner

commented May 17, 2018

Please reopen if you have additional questions.

@derhuerst derhuerst closed this May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.