所以,我是Grunt的新手。
我一直在玩grunt-contrib imagemin。
我注意到,当压缩PNG时,它做得很好。它平均压缩了80%的购买。
但是jpeg压缩几乎没有意义。它通常只压缩3mb图片中的几个KB。
我怎么做才能更好的压缩jpegs?
Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
build: {
src: 'src/*.js',
dest: 'build/main.min.js'
}
},
imagemin: {
png: {
options: {
optimizationLevel: 7
},
files: [
{
expand: true,
cwd: 'src/img/png/', // cwd is 'current working directory'
src: ['**/*.png'],
dest: 'build/img/png', // Could also match cwd.
ext: '.png'
}
]
},
jpg: {
options: {
progressive: true
},
files: [
{
expand: true, // Tell Grunt where to find our images and where to export them to.
cwd: 'src/img/', // cwd is 'current working directory'
src: ['**/*.jpg'],
dest: 'build/img', // Could also match cwd.
ext: '.jpg'
}
]
}
}
});
// Load the plugins
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
// Default tasks
grunt.registerTask('default', ['uglify', 'imagemin']);
};CLI
C:\Users\bmildren\Desktop\Sites\grunt-test>grunt
Running "uglify:build" (uglify) task
>> 1 file created.
Running "imagemin:png" (imagemin) task
? src/img/png/e4454c8df9.png (saved 1.37 MB)
Minified 1 image (saved 1.37 MB)
Running "imagemin:jpg" (imagemin) task
? src/img/5f468e98.jpg (saved 3.24 kB)
? src/img/photo-1414604582943-2fd913b3cb17.jpg (saved 3.24 kB)
? src/img/photo-1416424500327-a57ace7358b8.jpg (saved 3.24 kB)
? src/img/photo-1416838375725-e834a83f62b7.jpg (saved 3.24 kB)
? src/img/photo-1419332563740-42322047ff09.jpg (saved 3.24 kB)
Minified 5 images (saved 16.20 kB)
Done, without errors.
C:\Users\bmildren\Desktop\Sites\grunt-test>发布于 2015-06-17 08:27:46
grunt-contrib imagemin使用jpegtran来优化jpg文件。
它使用选项-copy none -optimize从文件中剥离元数据并优化Huffman table,这是一个无损的过程。
jpegtran不会执行有损操作,例如更改图像质量。因此,为了回答您的问题,您不能使用grunt-contrib-imagemin来进一步优化jpg文件,您需要使用其他工具。
png文件使用optipng进行优化,它能够应用不同的算法,这些算法对该文件类型似乎更有效,同时保持无损。
https://stackoverflow.com/questions/28093591
复制相似问题