Image processing 网页包4-生成响应图像
我想从一个基础图像生成不同大小的图像。F.e.我有一张1920x1080的图像,处理后我想要尺寸为(7681021601920)的图像 我知道有一种装载机可以实现这一点: 但是,我有许多“遗留”PHP应用程序(Zend Framework 3)的视图脚本,这些脚本不是由webpack(没有HtmlWebpackPlugin)处理的,因为它太复杂了,无法与Zend Framework一起工作 是否有一种方法,只需指向我的图像的源目录(glob),并将所有图像转换到那里,然后将它们(以及生成的版本)保存到我的dist文件夹中 我对ImageMin做了类似的操作:Image processing 网页包4-生成响应图像,image-processing,webpack-4,responsive-images,asset-management,Image Processing,Webpack 4,Responsive Images,Asset Management,我想从一个基础图像生成不同大小的图像。F.e.我有一张1920x1080的图像,处理后我想要尺寸为(7681021601920)的图像 我知道有一种装载机可以实现这一点: 但是,我有许多“遗留”PHP应用程序(Zend Framework 3)的视图脚本,这些脚本不是由webpack(没有HtmlWebpackPlugin)处理的,因为它太复杂了,无法与Zend Framework一起工作 是否有一种方法,只需指向我的图像的源目录(glob),并将所有图像转换到那里,然后将它们(以及生成的版本)
const
path = require('path'),
glob = require('glob'),
manifest = require('../manifest'),
ImageminWebpWebpackPlugin = require('imagemin-webp-webpack-plugin'),
ImageminPlugin = require('imagemin-webpack-plugin').default,
ImageminJpegoptim = require('imagemin-jpegoptim'),
ImageminOptipng = require('imagemin-optipng'),
Gifsicle = require('imagemin-gifsicle'),
CopyWebpackPlugin = require('copy-webpack-plugin');
// const files = glob.sync(path.join(manifest.paths.src, 'public/images/**/*.jpg'));
const quality = 50;
let copyOptions = [
{
context: path.join(manifest.paths.src, 'public/images/'),
from: '!(.tmb|captcha)/**/*',
to: path.join(manifest.paths.dist, 'images/'),
},
{
context: path.join(manifest.paths.src, 'public/images/'),
from: '*',
to: path.join(manifest.paths.dist, 'images/'),
}
];
// plugin config which gets passed to webpack config (pushed to plugins: [...])
module.exports = [
new CopyWebpackPlugin(copyOptions),
new ImageminWebpWebpackPlugin({
config: [{
test: /\.(jpe?g|png)/,
options: {
quality: quality
}
}],
overrideExtension: true,
detailedLogs: false,
strict: true
}),
new ImageminPlugin({
//disable: manifest.IS_DEVELOPMENT,
test: /\.(jpe?g|png|gif|svg)$/i,
cacheFolder: path.join(manifest.paths.src, 'public/.cache'),
plugins: [
ImageminJpegoptim({
// if you change this, do not foget to empty the cache folder!
max: quality
}),
ImageminOptipng({
optimizationLevel: 7
}),
Gifsicle({
optimizationLevel: 3
})
],
})
];
此配置将我的图像转换为web友好的大小(就文件大小而言!)。是否有机会在此配置中集成生成多个图像大小(尺寸!)的过程?有人有主意吗?