sindresorhus / gulp-imagemin

Minify PNG, JPEG, GIF and SVG images
MIT License
1.9k stars 156 forks source link

Corrupted image .jpg and .png #388

Open dovecancode opened 2 months ago

dovecancode commented 2 months ago

Hi,

I'm quite new to using gulp-imagemin. I don't have any issues with minifying SVGs, but I've noticed that when it comes to .jpg and .png files, the images appear corrupted after running the npx gulp command.

here is my gulpfile.js:

import gulp from 'gulp'
import imagemin from 'gulp-imagemin'

function taskImageMin() {
  return gulp
    .src('src/images/*.{jpg,png}')
    .pipe(imagemin())
    .on('data', function (file) {
      console.log('File processed:', file.path)
    })
    .pipe(gulp.dest('dist/images'))
}

export default taskImageMin

the output is on th left side and its corrupted or something like that

image

etherealHero commented 2 months ago

I also encountered this problem. What helped me was downgrading the imagemin version to 7.1.0. Accordingly, my package.json looks like this:

  "devDependencies": {
    "browser-sync": "^3.0.2",
    "del": "^6.0.0",
    "gulp": "^4.0.2",
    "gulp-htmlmin": "^5.0.1",
    "gulp-imagemin": "^7.1.0",
    "gulp-newer": "^1.4.0",
    "gulp-sass": "^5.0.0",
    "gulp-size": "^4.0.1",
    "gulp-sourcemaps": "^3.0.0",
    "sass": "^1.37.5"
  }
Applelo commented 1 month ago

Try to use encoding false, it solves my problem with corrupted files

gulp.src(paths.images.src, {encoding: false})

https://github.com/imagemin/imagemin/issues/418#issuecomment-2183917076