Fix image corruption with safer defaults, error handling, and integrity checks #395
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: Images (e.g., PNG, JPG) were being corrupted during optimization, likely due to aggressive compression settings or unhandled errors in the
gulp-imageminplugin. I found out this issue and observed in a custom implementation and potentially the main plugin.Fixes:
imagemin-mozjpeg: Setquality: 90(from a lower value) and enabledprogressive: truefor better compatibility.imagemin-optipng: SetoptimizationLevel: 3to avoid over-compression of PNGs.imagemin-gifsicle: ReducedoptimizationLevel: 2to prevent aggressive optimization.imagemin-svgo: Limited plugins to preserveviewBoxand avoid unintended changes.imagemin.bufferto catch and log optimization errors, returning the original file if optimization fails to prevent corruption.chalkfor better debugging, showing success, warnings, and errors.Testing:
gulpwith--verboseto verify logging and ensured optimized images rendered correctly in a browser and image viewer.filecommand (e.g.,file dist/assets/image.png).Impact:
--verbose) to debug issues.Additional Notes:
Checklist:
Please review and let me know if further adjustments are needed!