Skip to content

Commit 48e14f8

Browse files
committed
bugfix
1 parent 2867693 commit 48e14f8

File tree

23 files changed

+328
-22
lines changed

23 files changed

+328
-22
lines changed

.DS_Store

0 Bytes
Binary file not shown.

main.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const removeDoubles = async (images: string[], dontProcessAll?: boolean) => {
5555
let widthMap = {} as any
5656

5757
for (let i = 0; i < images.length; i++) {
58-
const metadata = await sharp(images[i]).metadata()
58+
const metadata = await sharp(images[i], {limitInputPixels: false}).metadata()
5959
const width = metadata.width || 0
6060
if (widthMap[width]) {
6161
widthMap[width] += 1
@@ -76,7 +76,7 @@ const removeDoubles = async (images: string[], dontProcessAll?: boolean) => {
7676
}
7777

7878
for (let i = 0; i < images.length; i++) {
79-
const metadata = await sharp(images[i]).metadata()
79+
const metadata = await sharp(images[i], {limitInputPixels: false}).metadata()
8080
const width = metadata.width || 0
8181
if (width > commonWidth * 1.5) {
8282
doubleImages.push(images[i])
@@ -89,16 +89,16 @@ const removeDoubles = async (images: string[], dontProcessAll?: boolean) => {
8989
}
9090

9191
for (let i = 0; i < doubleImages.length; i++) {
92-
const metadata = await sharp(doubleImages[i]).metadata()
92+
const metadata = await sharp(doubleImages[i], {limitInputPixels: false}).metadata()
9393
const width = metadata.width || 0
9494
const height = metadata.height || 0
9595
const newWidth = Math.floor(width / 2)
9696
const page1 = `${path.dirname(doubleImages[i])}/${path.basename(doubleImages[i], path.extname(doubleImages[i]))}.1${path.extname(doubleImages[i])}`
9797
const page2 = `${path.dirname(doubleImages[i])}/${path.basename(doubleImages[i], path.extname(doubleImages[i]))}.2${path.extname(doubleImages[i])}`
98-
await sharp(doubleImages[i])
98+
await sharp(doubleImages[i], {limitInputPixels: false})
9999
.extract({left: newWidth, top: 0, width: newWidth, height: height})
100100
.toFile(page1)
101-
await sharp(doubleImages[i])
101+
await sharp(doubleImages[i], {limitInputPixels: false})
102102
.extract({left: 0, top: 0, width: newWidth, height: height})
103103
.toFile(page2)
104104
}
@@ -701,14 +701,14 @@ const compress = async (info: any) => {
701701
const {frameArray, delayArray} = await functions.getGIFFrames(info.source)
702702
const newFrameArray = [] as Buffer[]
703703
for (let i = 0; i < frameArray.length; i++) {
704-
const newFrame = await sharp(frameArray[i])
704+
const newFrame = await sharp(frameArray[i], {limitInputPixels: false})
705705
.resize(width, height, {fit: "fill"})
706706
.toBuffer()
707707
newFrameArray.push(newFrame)
708708
}
709709
buffer = await functions.encodeGIF(newFrameArray, delayArray, width, height)
710710
} else {
711-
buffer = await sharp(buffer, {animated: true}).resize(width, height, {fit: "fill"}).gif().toBuffer()
711+
buffer = await sharp(buffer, {animated: true, limitInputPixels: false}).resize(width, height, {fit: "fill"}).gif().toBuffer()
712712
}
713713
if (options.quality !== 100) {
714714
buffer = await imagemin.buffer(buffer, {plugins: [
@@ -724,10 +724,10 @@ const compress = async (info: any) => {
724724
}
725725
} else {
726726
if (resizeCondition) {
727-
buffer = await sharp(buffer, {animated: true}).resize(width, height, {fit: "fill"}).toBuffer()
727+
buffer = await sharp(buffer, {animated: true, limitInputPixels: false}).resize(width, height, {fit: "fill"}).toBuffer()
728728
}
729729
if (sourceExt !== ext) {
730-
let s = sharp(buffer, {animated: true})
730+
let s = sharp(buffer, {animated: true, limitInputPixels: false})
731731
if (ext === "jpg" || ext === "jpeg") s.jpeg({optimiseScans: options.progressive, quality: options.quality})
732732
if (ext === "png") s.png({quality: options.quality})
733733
if (ext === "webp") s.webp({quality: options.quality})
@@ -819,14 +819,14 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
819819
const {frameArray, delayArray} = await functions.getGIFFrames(info.source)
820820
const newFrameArray = [] as Buffer[]
821821
for (let i = 0; i < frameArray.length; i++) {
822-
const newFrame = await sharp(frameArray[i])
822+
const newFrame = await sharp(frameArray[i], {limitInputPixels: false})
823823
.resize(width, height, {fit: "fill"})
824824
.toBuffer()
825825
newFrameArray.push(newFrame)
826826
}
827827
buffer = await functions.encodeGIF(newFrameArray, delayArray, width, height)
828828
} else {
829-
buffer = await sharp(buffer, {animated: true}).resize(width, height, {fit: "fill"}).gif().toBuffer()
829+
buffer = await sharp(buffer, {animated: true, limitInputPixels: false}).resize(width, height, {fit: "fill"}).gif().toBuffer()
830830
}
831831
if (options.quality !== 100) {
832832
buffer = await imagemin.buffer(buffer, {plugins: [
@@ -842,10 +842,10 @@ ipcMain.handle("compress-realtime", async (event, info: any) => {
842842
}
843843
} else {
844844
if (resizeCondition) {
845-
buffer = await sharp(buffer, {animated: true}).resize(width, height, {fit: "fill"}).toBuffer()
845+
buffer = await sharp(buffer, {animated: true, limitInputPixels: false}).resize(width, height, {fit: "fill"}).toBuffer()
846846
}
847847
if (sourceExt !== ext) {
848-
let s = sharp(buffer, {animated: true})
848+
let s = sharp(buffer, {animated: true, limitInputPixels: false})
849849
if (ext === "jpg" || ext === "jpeg") s.jpeg({optimiseScans: options.progressive, quality: options.quality})
850850
if (ext === "png") s.png({quality: options.quality})
851851
if (ext === "webp") s.webp({quality: options.quality})

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "image-compressor",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Compresses, resizes, and renames images.",
55
"main": "dist/main.js",
66
"scripts": {
77
"start": "npm run clean && webpack && cross-env DEVELOPMENT=true electron dist/main.js",
88
"clean": "del-cli ./dist",
9-
"build": "npm run clean ./build && webpack && npm run sharp:mac && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -m -p never",
9+
"build": "npm run clean ./build && webpack && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -m -p never",
1010
"rebuild": "npm rebuild --runtime=electron --target=14.0.0 --disturl=https://atom.io/download/atom-shell --abi=83",
1111
"release": "npm run release:mac && npm run release:win",
1212
"release:mac": "npm run clean ./build && webpack && npm run sharp:mac && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder -m -p always",
@@ -46,11 +46,23 @@
4646
"extraFiles": [
4747
"poppler/mac/**"
4848
],
49-
"files": [
50-
"vendor/cjpeg",
51-
"vendor/cwebp",
52-
"vendor/gifsicle",
53-
"vendor/pngquant"
49+
"extraResources": [
50+
{
51+
"from": "vendor/cjpeg",
52+
"to": "app/vendor/cjpeg"
53+
},
54+
{
55+
"from": "vendor/cwebp",
56+
"to": "app/vendor/cwebp"
57+
},
58+
{
59+
"from": "vendor/gifsicle",
60+
"to": "app/vendor/gifsicle"
61+
},
62+
{
63+
"from": "vendor/pngquant",
64+
"to": "app/vendor/pngquant"
65+
}
5466
]
5567
},
5668
"dmg": {

patch/.DS_Store

0 Bytes
Binary file not shown.

patch/cwebp-bin/.DS_Store

0 Bytes
Binary file not shown.

patch/cwebp-bin/cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
import process from 'node:process';
3+
import {spawn} from 'node:child_process';
4+
import binPath from './index.js';
5+
6+
spawn(binPath, process.argv.slice(2), {stdio: 'inherit'})
7+
.on('exit', process.exit);

patch/cwebp-bin/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import lib from './lib/index.js';
2+
3+
export default lib.path();

patch/cwebp-bin/lib/install.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import process from 'node:process';
2+
import {fileURLToPath} from 'node:url';
3+
import binBuild from 'bin-build';
4+
import bin from './index.js';
5+
6+
bin.run(['-version']).then(() => {
7+
console.log('cwebp pre-build test passed successfully');
8+
}).catch(error => {
9+
console.warn(error.message);
10+
console.warn('cwebp pre-build test failed');
11+
console.info('compiling from source');
12+
13+
try {
14+
const source = fileURLToPath(new URL('../vendor/source/libwebp-1.2.1.tar.gz', import.meta.url));
15+
16+
binBuild.file(source, [
17+
`./configure --disable-shared --prefix="${bin.dest()}" --bindir="${bin.dest()}"`,
18+
'make && make install',
19+
]);
20+
21+
console.log('cwebp built successfully');
22+
} catch (error) {
23+
console.error(error.stack);
24+
25+
// eslint-disable-next-line unicorn/no-process-exit
26+
process.exit(1);
27+
}
28+
});

patch/cwebp-bin/license

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Imagemin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)