パッケージの詳細

@localnerve/gulp-responsive

localnerve506MIT7.3.1

small patch for gulp-responsive

gulpplugin, gulp, sharp, responsive

readme

gulp-responsive

Verify

This is the same as the original except with updated dependencies and code

Generates images at different sizes

Installation

gulp-responsive depends on sharp. Sharp is one of the fastest Node.js modules for resizing JPEG, PNG, WebP and TIFF images.

If you are using Mac OS then before installing gulp-responsive you should install the libvips library. Further information and instructions can be found in the sharp installation guide.

$ npm install --save-dev gulp-responsive

Usage

import gulp from 'gulp'
import responsive from 'gulp-responsive'

gulp.task('default', function () {
  return gulp
    .src('src/*.{png,jpg}')
    .pipe(
      responsive({
        'background-*.jpg': {
          width: 700,
          quality: 50
        },
        'cover.png': {
          width: '50%',
          // convert to jpeg format
          format: 'jpeg',
          rename: 'cover.jpg'
        },
        // produce multiple images from one source
        'logo.png': [
          {
            width: 200
          },
          {
            width: 200 * 2,
            rename: 'logo@2x.png'
          }
        ]
      })
    )
    .pipe(gulp.dest('dist'))
})

Examples

Integration

All together :fireworks:

API

responsive(config, options)

config

Configuration can be provided in one of the following formats:

1. Array of unique configurations
;[
  {
    name: 'logo.png',
    width: 200,
    height: 100
  },
  {
    name: 'banner.png',
    width: 500
  }
]
2. Object of unique configurations. Keys are filenames.
{
  'logo.png': {
    width: 300,
    height: 200,
    rename: 'logo@2x.png'
  },
  'background-*.png': {
    width: 1400,
    withoutEnlargement: true
  }
}
3. Object of arrays of unique configurations. Keys are filenames.
{
  'logo.png': [{
      width: 200,
      rename: 'logo@1x.png'
    },{
      width: 400,
      rename: 'logo@2x.png'
    }],
  'background-*': [{
    height: 400
  }]
}

Configuration unit

Configuration unit is an object:

  • name: String — filename glob pattern.
  • width: Number or String — width in pixels or percentage of the original, not set by default.
  • height: Number or String — height in pixels or percentage of the original, not set by default.
  • withoutEnlargement: Boolean — do not enlarge the output image, default true.
  • skipOnEnlargement: Boolean — do not write an output image at all if the original image is smaller than the configured width or height, default false.
  • min: Boolean — preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to the width and height specified.
  • max: Boolean — resize to the max width or height the preserving aspect ratio (both width and height have to be defined), default false.
  • quality: Number — output quality for JPEG, WebP and TIFF, default 80.
  • progressive: Boolean — progressive (interlace) scan for JPEG and PNG output, default false.
  • withMetadata: Boolean — include image metadata, default false.
  • compressionLevel: Number — zlib compression level for PNG, default 6.
  • rename: String, Object or Function — renaming options, file will not be renamed by default. When extname is specified, output format is parsed from extension. You can override this autodetection with format option.
  • format: String — output format jpeg, png, webp or raw, default is null.
  • crop: Crop the resized image to the exact size specified, default is false.
  • embed: Preserving aspect ratio, resize the image to the maximum width or height specified then embed on a background of the exact width and height specified, default is false.
  • ignoreAspectRatio: Boolean — Ignoring the aspect ratio of the input, stretch the image to the exact width and/or height provided via resize, default is false.
  • kernel: String — The kernel to use for image reduction, defaulting to lanczos3.
  • background: Color — Set the background for the embed and flatten operations, '#default is fff'.
  • flatten: Boolean — Merge alpha transparency channel, if any, with background, default is false.
  • negate: Boolean — Produces the "negative" of the image, default is false.
  • rotate: Boolean — Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag, default is false.
  • flip: Boolean — Flip the image about the vertical Y axis. This always occurs after rotation, if any. The use of flip implies the removal of the EXIF Orientation tag, if any. Default is false.
  • flop: Boolean — Flop the image about the horizontal X axis. This always occurs after rotation, if any. The use of flop implies the removal of the EXIF Orientation tag, if any. Default is false.
  • blur: Boolean — When used without parameters, performs a fast, mild blur of the output image. This typically reduces performance by 10%. Default is false.
  • sharpen: Boolean — When used without parameters, performs a fast, mild sharpen of the output image. This typically reduces performance by 10%. Default is false.
  • threshold: Number or Boolean — Converts all pixels in the image to greyscale white or black, default is false.
  • gamma: Boolean — Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of 1/gamma then increasing the encoding (brighten) post-resize at a factor of gamma. Default is false.
  • grayscale: Boolean — Convert to 8-bit greyscale; 256 shades of grey, default is false.
  • normalize: Boolean — Enhance output image contrast by stretching its luminance to cover the full dynamic range. This typically reduces performance by 30%. Default is false.
  • trim: Boolean or Number — Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel. Default is false.
  • tile: Boolean or Object — The size and overlap, in pixels, of square Deep Zoom image pyramid tiles, default is false.
  • withoutChromaSubsampling: Boolean — Disable the use of chroma subsampling with JPEG output (4:4:4), default is false.

Detailed description of each option can be found in the sharp API documentation.

Renaming

Renaming is implemented by the rename module. Options correspond with options of gulp-rename.

options

errorOnUnusedConfig

Type: Boolean
Default: true

Emit the error when configuration is not used.

errorOnUnusedImage

Type: Boolean
Default: true

Emit the error when image is not used.

passThroughUnused

Type: Boolean
Default: false

Keep unmatched images in the stream. To use this option errorOnUnusedImage should be false.

errorOnEnlargement

Type: Boolean
Default: true

Emit the error when image is enlarged.

stats

Type: Boolean
Default: true

Show statistics after the run — how many images were created, how many were matched and how many were in the run in total.

silent

Type: Boolean
Default: false

Silence messages and stats if 0 images were created. If you wish to supress all messages and stats, set the options.stats to false as well.

postprocess

Type: Function
Default: undefined

If you supply a postprocess function, it will be called after every successfully processed file. It receives a vinyl object of the original file, the config used to process it, and a vinyl object of the new file. For Vinyl object details, see vinyl.

Signature: function postprocess (originalVinylFile, config, newVinylFile)

Global Configuration Options

You can specify global default value for any of the configuration options.

gulp.task('default', function () {
  return gulp
    .src('src/*.png')
    .pipe(
      responsive(config, {
        // global quality for all images
        quality: 50,
        errorOnUnusedImage: false
      })
    )
    .pipe(gulp.dest('dist'))
})

License

MIT © Evgeny Vlasenko

更新履歴

7.3.1

  • Update sharp to 0.34.1

7.3.0

  • Update sharp to 0.34.0

7.2.0

  • add config to postprocess

7.1.0

  • add postprocess feature

7.0.1

  • update devdeps
  • update usage of file-type in test

7.0.0

  • Node 20+
  • minimatch@^10.0.1

6.2.0

  • Update chalk to 5.4.1

6.1.6

  • Update sharp to 0.33.5

6.1.4

  • Update sharp to 0.33.4

6.1.2

  • Update sharp to 0.33.3

6.1.1

  • Update sharp to 0.33.2

6.1.0

  • Update sharp to 0.33.1

6.0.1

  • Update sharp to 0.32.6

6.0.0

  • Switch to eslint
  • Node 18+
  • Update sharp to 0.32.5

5.0.0

  • Update sharp to 0.32.1
  • Update all dependencies
  • Remove through2 dependency
  • Switch to esm
  • Node 16+

4.0.0 / 2023-02-10

  • Update sharp to 0.31.3
  • Update all dependencies, remove unused or replacable deps
  • Node 14+

3.0.0 / 2019-10-12

  • Suport for sharp 0.23.1 #129
  • Remove support for Node.js 6 #129
  • Support for Node.js 8,10,12 #129
  • Refactor codebase #129
  • Avoid renaming extname #116
  • Fix value for chroma subsampling setting #116

2.6.0 / 2016-09-15

  • add: kernel option
  • rename: interpolation to interpolator option
  • deprecate: interpolation option

    2.5.0 / 2016-06-01

  • deps: sharp@0.16.0 http://sharp.dimens.io/en/stable/changelog/#v016-pencil

  • deps: async@2.0.1
  • deps: mocha@3.0.2

    2.4.0 / 2016-06-01

  • deps: sharp@0.15.0 http://sharp.dimens.io/en/stable/changelog/#v015-outfit

  • breaking: Existing sharpen API to accept sigma

    2.3.0 / 2016-04-15

  • deps: sharp@0.14.0 http://sharp.dimens.io/en/stable/changelog/#v014-needle

    2.2.0 / 2016-03-18

  • add: silent option

  • add: stats option

    2.1.0 / 2016-02-18

  • deps: sharp@0.13.0

  • deps: lodash@4.5

    2.0.0 / 2016-01-09

  • Version 2.0 https://github.com/mahnunchik/gulp-responsive/issues/23

  • add: all sharp options
  • add: better usage examples
  • add: ability to transform format of output image (format option)
  • remove: depricated options strictMatchConfig and strictMatchImages
  • add: visibility to image manipulation process

    1.2.1 / 2015-08-18

  • add: skipOnEnlargement option

    1.2.0 / 2015-08-15

  • deps: sharp@0.11 through2@2

    1.1.0 / 2015-05-24

  • add: passThroughUnused option to pass through unmatched files

  • rename: options strictMatchConfig to errorOnUnusedConfig and strictMatchImages to errorOnUnusedImage
  • deps: sharp@^0.10.0, rename@^1.0.3, async@^1.0.0

    1.0.7 / 2015-02-16

  • add: max option, see sharp#max

    1.0.6 / 2015-02-08

  • add: node 0.12 and latest iojs to travis

    1.0.5 / 2015-01-28

  • update: sharp 0.9.0

  • update: minimatch and lodash

    1.0.4 / 2014-11-23

  • add: ability to use size as a percentage

    1.0.3 / 2014-11-19

  • add: global config feature

    1.0.2 / 2014-11-11

  • add: renaming feature by rename module https://www.npmjs.org/package/rename

1.0.1 / 2014-11-03

  • add: config options: quality, progressiv, withMetadata, compressionLevel
  • fix: merge config behavior

1.0.0 / 2014-10-29

  • basic implementation