Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@hugsmidjan/gulp-images

hugsmidjan32ISC0.2.4TypeScript support: included

Image minification gulp task

readme

@hugsmidjan/gulp-images

npm install --save-dev @hugsmidjan/gulp-images

Usage

const [imagesCompress, imagesWatch] = require('@hugsmidjan/gulp-images')(
  opts
);

API / Advanced usage

const imagesTaskFactory = require('@hugsmidjan/gulp-images');

const options = {
  // These are the defaults:
  name: 'images', // the display name of the generated tasks
  src: 'src/',
  dist: 'pub/',
  glob: ['i/**/*', '!i/_raw/**'], // which files to glob up as entry points
  // svg_keepIds: false, // Treat all SVG `id=`s as significant content
  // svgoRules: {}, // SVGO settings (https://github.com/svg/svgo#what-it-can-do)
};

// Create the gulp tasks based on the above options.
const imagesTasks = imagesTaskFactory(options);

// imagesTasks is a two item array...
const [imagesCompress, imagesWatch] = imagesTasks;
// ...but it also exposes the tasks as named properties.
const { compress, watch } = imagesTasks;

Magic file-name compression hints

PNG and JPEG images can be forced through a lossy compression via a ---q{N} file-name suffix. The suffix is stripped from the filename before saving in the dist folder.

In SVG files all ID attributes are stripped away unless a svg_keepIds: true option is passed, or if an individual SVG file has a ---ids file-name suffix - which then gets stripped away before saving.

Examples:

  • src/i/photo---q60.jpg (100% quality original) ---> dist/i/photo.png (recompressed to approx. 60% quality)
  • src/i/image---q50.png (24bit file) ---> dist/i/image.png (png8 with at least 50% quality)
  • src/i/image---q50-70.png (24bit file) ---> dist/i/image.png (png8 with between 50% and 70% quality)
  • src/i/image---q50--d0.png (24bit file) ---> dist/i/image.png (png8 with at least 50% quality - no dithering)
  • src/i/image---ids.svg (keep ID attributes) ---> dist/i/image.svg (with ID attributes intact)

changelog

Change Log

Upcoming...

  • ...

0.2.4

2024-01-30

  • feat: Add TypeScript types and JSDoc comments

0.2.3

2024-01-27

  • feat: Make watch task return a node FSWatcher object

0.2.2

2022-04-28

  • fix: Task ended before all images had been compressed

0.2.0 — 0.2.1

2022-04-19

  • feat: Update deps for more reliable modern node version support

0.1.8

2020-09-18

  • fix: Correctly apply svgo plugins as array of single-key objects. o_O

0.1.7

2020-08-12

  • fix: Default to retaining the viewBox attribute on SVG images

0.1.6

2020-06-18

  • feat: Add svgoRules option

0.1.5

2019-12-10

  • fix: Bad glob pattern

0.1.4

2019-11-22

  • feat: Only pass compressible files to imagemin – just copy others

0.1.3

2019-07-09

  • chore: Upgrade dependencies to latest versions

0.1.2

2019-05-17

  • feat: Use chokidar events to speed up watch task
  • fix: Console log lossy-compression events outside of imagemin code path

0.1.1

2019-05-17

  • feat: Use gulp-changed to speed up the watch task

0.1.0

2019-05-17

  • feat: Initial commit