Search code examples
gulp-imageminimagemin

Gulp-imagemin: how to preserve EXIF?


Is there a way to preserve metadata such as EXIF? I have been unable to find an option for this.


Solution

  • The different imagemin plugins have different settings.

    jpegoptim:

    gulp.task('compressjpegoptim', () => {
      gulp
      .src('./images/*.jpg')
      .pipe(imagemin([imageminJpegoptim({
        stripAll: false,
        stripExif: false,
      })]))
      .pipe(gulp.dest('./dist'))
    });
    

    jpegtran

    imagemin-jpegtran specifically ask jpegtran to remove the markers, with no options to keep them. If you modify this line in the source from 'none' to 'all' it will keep the Exif markers. This can be seen in jpegtran's documentation (search for Exif).

    mozjpeg

    This plugin seems to keep the Exif by default.