Skip to content

Consider adding a Gulp task for image optimization #183

@mgburns

Description

@mgburns

@NathanHass Has been using this one a bunch:

const resizeImages = async function() {
  const sizes = [
    { width: 320, quality: 0.9, suffix: '' },
    { width: 640, quality: 0.9, suffix: '-640' },
    { width: 768, quality: 0.9, suffix: '-768' },
    { width: 1024, quality: 0.9, suffix: '-1024' },
    { width: 1440, quality: 0.9, suffix: '-1440' },
  ];

  let stream;

  sizes.forEach(size => {
    stream = src('src/img/**/*.{jpg,png}')
      //     resize image
      .pipe(
        imageResize({
          width: size.width,
          upscale: false,
          quality: size.quality,
        }),
      )
      //       add suffix to image
      .pipe(
        rename(path => {
          path.basename += `${size.suffix}`;
        }),
      )
      //     output optimized images to a destination folder
      .pipe(dest('dist/static/img'));
  });
  return stream;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions