Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a Gulp task for image optimization #183

Open
mgburns opened this issue Nov 2, 2022 · 1 comment
Open

Consider adding a Gulp task for image optimization #183

mgburns opened this issue Nov 2, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@mgburns
Copy link
Member

mgburns commented Nov 2, 2022

@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;
};
@mgburns mgburns added the enhancement New feature or request label Nov 2, 2022
@NathanHass
Copy link

☝🏻 just noting that we'll need to add two npm packages, gulp-rename and gulp-image-resize.

We also might want to add a responsive image component that uses these sizes (and maybe lazyloads by default!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants