Skip to content

Commit

Permalink
enable trellisQuantisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Moebits committed Oct 1, 2024
1 parent 48e14f8 commit fa4b437
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Binary file modified .DS_Store
Binary file not shown.
40 changes: 18 additions & 22 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,17 +726,15 @@ const compress = async (info: any) => {
if (resizeCondition) {
buffer = await sharp(buffer, {animated: true, limitInputPixels: false}).resize(width, height, {fit: "fill"}).toBuffer()
}
if (sourceExt !== ext) {
let s = sharp(buffer, {animated: true, limitInputPixels: false})
if (ext === "jpg" || ext === "jpeg") s.jpeg({optimiseScans: options.progressive, quality: options.quality})
if (ext === "png") s.png({quality: options.quality})
if (ext === "webp") s.webp({quality: options.quality})
if (ext === "avif") s.avif({quality: options.quality})
if (ext === "jxl") s.jxl({quality: options.quality})
if (ext === "gif") s.gif()
buffer = await s.toBuffer()
}
if (options.quality !== 100) {
let s = sharp(buffer, {animated: true, limitInputPixels: false})
if (ext === "jpg" || ext === "jpeg") s.jpeg({optimiseScans: options.progressive, quality: options.quality, trellisQuantisation: true})
if (ext === "png") s.png({quality: options.quality})
if (ext === "webp") s.webp({quality: options.quality})
if (ext === "avif") s.avif({quality: options.quality})
if (ext === "jxl") s.jxl({quality: options.quality})
if (ext === "gif") s.gif()
buffer = await s.toBuffer()
if (options.quality < 95) {
if (!isAnimated && ext !== "avif" && ext !== "jxl") {
buffer = await imagemin.buffer(buffer, {plugins: [
imageminMozjpeg({quality: options.quality}),
Expand Down Expand Up @@ -844,17 +842,15 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
if (resizeCondition) {
buffer = await sharp(buffer, {animated: true, limitInputPixels: false}).resize(width, height, {fit: "fill"}).toBuffer()
}
if (sourceExt !== ext) {
let s = sharp(buffer, {animated: true, limitInputPixels: false})
if (ext === "jpg" || ext === "jpeg") s.jpeg({optimiseScans: options.progressive, quality: options.quality})
if (ext === "png") s.png({quality: options.quality})
if (ext === "webp") s.webp({quality: options.quality})
if (ext === "avif") s.avif({quality: options.quality})
if (ext === "jxl") s.jxl({quality: options.quality})
if (ext === "gif") s.gif()
buffer = await s.toBuffer()
}
if (options.quality !== 100) {
let s = sharp(buffer, {animated: true, limitInputPixels: false})
if (ext === "jpg" || ext === "jpeg") s.jpeg({optimiseScans: options.progressive, quality: options.quality})
if (ext === "png") s.png({quality: options.quality})
if (ext === "webp") s.webp({quality: options.quality})
if (ext === "avif") s.avif({quality: options.quality})
if (ext === "jxl") s.jxl({quality: options.quality})
if (ext === "gif") s.gif()
buffer = await s.toBuffer()
if (options.quality < 95) {
if (!isAnimated && ext !== "avif" && ext !== "jxl") {
buffer = await imagemin.buffer(buffer, {plugins: [
imageminMozjpeg({quality: options.quality}),
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "image-compressor",
"version": "0.2.2",
"version": "0.2.3",
"description": "Compresses, resizes, and renames images.",
"main": "dist/main.js",
"scripts": {
Expand Down

0 comments on commit fa4b437

Please sign in to comment.