1200 byte savings in some cases with gifs
This commit is contained in:
parent
7b04c35c94
commit
e68ad369e9
1 changed files with 22 additions and 7 deletions
|
@ -35,15 +35,30 @@ export default class ImageOptimization extends Plugin {
|
|||
data = await sharp(file).png({ quality: 100 }).toBuffer();
|
||||
}
|
||||
if (type == "gif") {
|
||||
// not heavy optimizations, not a fan tbf, but whatever :shrug:
|
||||
data = await sharp(file, { animated: true })
|
||||
.gif({ colors: 16 })
|
||||
.toBuffer();
|
||||
const gif = sharp(file, { animated: true });
|
||||
const pageCount = (await gif.metadata()).pages;
|
||||
if (pageCount == 1) {
|
||||
data = await sharp(file, { animated: false })
|
||||
.gif({ colors: 16 })
|
||||
.toBuffer();
|
||||
} else {
|
||||
data = await sharp(file, { animated: true })
|
||||
.gif({ colors: 16 })
|
||||
.toBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
if(nonOptimized.byteLength < data.byteLength) {
|
||||
if(this.logging) {
|
||||
console.log("❌ " + filePath + "("+nonOptimized.byteLength+"B) optimized was " + data.byteLength + "B. It has been skipped.");
|
||||
if (nonOptimized.byteLength < data.byteLength) {
|
||||
if (this.logging) {
|
||||
console.log(
|
||||
"❌ " +
|
||||
filePath +
|
||||
"(" +
|
||||
nonOptimized.byteLength +
|
||||
"B) optimized was " +
|
||||
data.byteLength +
|
||||
"B. It has been skipped."
|
||||
);
|
||||
}
|
||||
data = nonOptimized;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue