derhuerst / gulp-scale-images

Gulp plugin to resize each image into multiple smaller variants.
https://github.com/derhuerst/gulp-scale-images#gulp-scale-images
ISC License
13 stars 5 forks source link

Invalid input | When you try to get meta #28

Closed k1ll1n closed 3 years ago

k1ll1n commented 3 years ago

With this code, I get the error "Invalid input"

const readMetadata = require('gulp-scale-images/read-metadata')
const through = require('through2')
const scaleImages = require('gulp-scale-images')

const computeScaleInstructions = (file, _, cb) => {
    readMetadata(file.path, (err, meta) => {
        if (err) return cb(err)
        file = file.clone()
        file.scale = {
            maxWidth: Math.floor(meta.width / 2),
            maxHeight: Math.floor(meta.height / 2)
        }
        cb(null, file)
    })
}

gulp.src(…)
.pipe(through.obj(computeScaleInstructions))
.pipe(scaleImages())
.pipe(gulp.dest(…))
[14:25:15] Error: Invalid input
    at Sharp (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/sharp/lib/constructor.js:158:11)
    at Object.readMetadata (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/gulp-scale-images/read-metadata.js:6:2)
    at Transform.computeScaleInstructions [as _transform] (/home/killin/WebstormProjects/akadem-klubb_2.0/gulpfile.js:132:17)
    at Transform._read (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at Transform._write (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:164:83)
    at doWrite (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:409:139)
    at writeOrBuffer (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:398:5)
    at Transform.Writable.write (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:307:11)
    at DestroyableTransform.ondata (/home/killin/WebstormProjects/akadem-klubb_2.0/node_modules/readable-stream/lib/_stream_readable.js:619:20)
    at DestroyableTransform.emit (events.js:315:20)
derhuerst commented 3 years ago

Please provide more details:

hyvyys commented 3 years ago

I'm getting this too so I'll chime in.

Node:

v14.16.0

npm.ls.txt

Happens with any image, so I'm not sure how the vinyl would help. And if that matters, I'm on macOS Big Sur.

derhuerst commented 3 years ago

I can run example.js within this repo just fine, using Node.js v14.17.3.

Have you double-checked that you're only sending images into gulp-scale-images? You can debug files in a Gulp pipeline using gulp-debug.

IAluI commented 3 years ago

@derhuerst Hi! readme.md contains wrong example. The function readMetadata takes as its first argument Vinyl file instance. But in sample it take in first argement a string - file.path. Because of this people has this error.

derhuerst commented 3 years ago

Thanks @k1ll1n for reporting this, and thanks @IAluI for resolving this!