2024-11-05|今天我做了什么
图片转换
使用 sip 将 JPG 图片转为 PNG
macos 上先安装 sip:
brew install sip
然后批量执行:
for file in *.jpg; do
sips -s format png "$file" --out "${file%.jpg}.png"
done
for file in *.jpeg; do
sips -s format png "$file" --out "${file%.jpeg}.png"
done
for file in *.JPG; do
sips -s format png "$file" --out "${file%.JPG}.png"
done
rm -rf *.jpeg *.jpg *.JPG
使用 imagemin 将 jpg、png 转换为 webp
import imagemin from "imagemin";
import imageminWebp from "imagemin-webp";
import imageminPngquant from "imagemin-pngquant";
(async () => {
let fullImages = await convertFullImages();
let previewImages = await convertPreviewImages();
let total = fullImages.length + previewImages.length;
console.log('Converted ' + total + ' images to WEBP format.');
})();
function convertFullImages(){
return imagemin(['static/raw-images/*.{jpg,jpeg,JPG,png}'], {
destination: 'static/images',
plugins: [
imageminWebp({quality: 85})
]
});
}
function convertPreviewImages(){
return imagemin(['static/raw-images/*.{jpg,jpeg,png}'], {
destination: 'static/preview-images',
plugins: [
imageminWebp({
resize: {
width: 600,
height: 340
}
})
]
});
}
Related content
- 2024-11-13|今天我做了什么
- 2024-11-07|今天我做了什么
- 2024-11-06|今天我做了什么
- 2024-11-04|SivaLabs博客文章
- 2024-02-20|RateLimitAspect请求限流、调整spring-cloud-examples项目结构
- 2024-02-19|foodie-cloud集成Sharding Sphere实现读写分离
- 2024-02-18|NewRelice应用性能监控、6个Diagrams工具、foodie-food测试
- 2024-02-05|Spring Cloud Config快速入门
- 2024-02-04|foodie-cloud集成Resilience4j
- 2024-02-02|foodie-cloud集成Spring Cloud Config和SpringDoc