mahnunchik / gulp-responsive

gulp-responsive generates images at different sizes
https://npmjs.com/gulp-responsive
MIT License
502 stars 62 forks source link

Error on smaller images #148

Open djmtype opened 4 years ago

djmtype commented 4 years ago

If one of my images happens to be smaller than the smallest size (576px) setting, I get an error and the gulp images task stops performing.

[11:27:13] 'images' errored after 641 ms
[11:27:13] Error in plugin "gulp-responsive"
Error
    at DestroyableTransform.through2Handler [as _transform] (/Users/me/Sites/_image-transforms/node_modules/gulp-responsive/lib/index.js:98:14)

My gulpfile:

var gulp = require('gulp')
var responsive = require('gulp-responsive')
gulp.task('images', function() {
    return gulp
        .src('src/img/*.{jpg,png}')
        .pipe(
            responsive({
                '*.jpg': [{
                        width: 576,
                        rename: {
                            suffix: '-sm'
                        }
                    },
                    {
                        width: 768,
                        rename: {
                            suffix: '-md'
                        }
                    },
                    {
                        width: 1024,
                        rename: {
                            suffix: '-lg'
                        }
                    },
                    {
                        width: 1200,
                        rename: {
                            suffix: '-xl'
                        }
                    },
                    {
                        rename: {
                            suffix: ''
                        }
                    },
                ],
            }, {
                quality: 70,
                progressive: true,
                compressionLevel: 5,
                withMetadata: false,
                withoutEnlargement: true,
                skipOnEnlargement: false, 
            })
        )
        .pipe(gulp.dest('dist'))
})
djmtype commented 4 years ago

BTW, I've tried variations of these settings:

withoutEnlargement: true,
skipOnEnlargement: true,
germolinal commented 3 years ago

Same here.

menteora commented 3 years ago

withoutEnlargement: false,

works for me.

cssagogo commented 3 years ago

I'm seeing similar error when any size is provided and a matching image is smaller...

         .pipe(
            responsive({
                '**/*.png': [
                { width: 480, rename: { suffix: '-480px', extname: '.jpg' }, withoutEnlargement: true },
                { width: 640, rename: { suffix: '-640px', extname: '.jpg' }, withoutEnlargement: true },
                { width: 997, rename: { suffix: '-997px', extname: '.jpg' }, withoutEnlargement: true }, // Succeeds on 997px image.
                { width: 998, rename: { suffix: '-998px', extname: '.jpg' }, withoutEnlargement: true }, // Fails on 997px image.    
                ]
            },
            {
                // Global configuration for all images
                // The output quality for JPEG, WebP and TIFF output formats
                quality: 70,
                // Use progressive (interlace) scan for JPEG and PNG output
                progressive: true,
                // Zlib compression level of PNG output format
                compressionLevel: 6,
                // Strip all metadata
                withMetadata: false
            })
        )

And the console output when it fails...

    [23:41:55] 'imgBuild' errored after 594 ms
    [23:41:55] Error in plugin "gulp-responsive"
    Error at DestroyableTransform.through2Handler [as _transform] (/node_modules/gulp-responsive/lib/index.js:98:14)

    (sharp:3898): GLib-CRITICAL **: 23:41:55.402: g_hash_table_lookup: assertion 'hash_table != NULL' failed

    (sharp:3898): GLib-CRITICAL **: 23:41:55.402: g_hash_table_lookup: assertion 'hash_table != NULL' failed

    (sharp:3898): GLib-CRITICAL **: 23:41:55.403: g_hash_table_lookup: assertion 'hash_table != NULL' failed

    (sharp:3898): GLib-CRITICAL **: 23:41:55.403: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed

    (sharp:3898): GLib-CRITICAL **: 23:41:55.403: g_hash_table_lookup: assertion 'hash_table != NULL' failed
    Segmentation fault (core dumped)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 139
    npm ERR! mySite@0.1.0 gulp: `gulp "imgBuild"`
    npm ERR! Exit status 139
    npm ERR! 
    npm ERR! Failed at the mySite@0.1.0 gulp script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/vagrant/.npm/_logs/2021-08-06T23_41_55_603Z-debug.log