Skip to content

Commit 391eec1

Browse files
Replace sharp with jimp (#325)
* #44449: replace sharp with jimp * #44449: update sharp download script * #44449: add darwin-arm64 build * Revert "#44449: add darwin-arm64 build" This reverts commit d6bae5f. * remove sharp scripts
1 parent 617be3d commit 391eec1

File tree

7 files changed

+529
-145
lines changed

7 files changed

+529
-145
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
ARCH = darwin-x64-unknown
44
SKIP_CHROMIUM =
55
OUT =
6-
SKIP_SHARP_DOWNLOAD =
76
DOCKER_TAG = dev
87

98
all: clean build
@@ -24,7 +23,7 @@ clean_package:
2423
./scripts/clean_target.sh ${ARCH} ${OUT}
2524

2625
package:
27-
./scripts/package_target.sh ${ARCH} ${SKIP_CHROMIUM} ${OUT} ${SKIP_SHARP_DOWNLOAD}
26+
./scripts/package_target.sh ${ARCH} ${SKIP_CHROMIUM} ${OUT}
2827

2928
archive:
3029
./scripts/archive_target.sh ${ARCH} ${OUT}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"puppeteer": "^13.1.3",
3535
"puppeteer-cluster": "^0.22.0",
3636
"poolpeteer": "^0.22.0",
37-
"sharp": "0.29.3",
37+
"jimp": "0.16.1",
3838
"unique-filename": "^1.1.0",
3939
"winston": "^3.2.1"
4040
},

scripts/download_sharp.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

scripts/package_target.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@
33
ARCH="${1:-}"
44
SKIP_CHROMIUM=${2:-false}
55
OUT="${3:-}"
6-
SKIP_SHARP_DOWNLOAD=${4:-false}
76

87
if [ -z "$ARCH" ]; then
98
echo "ARCH (arg 1) has to be set"
109
exit 1
1110
fi
1211

13-
if [ ${SKIP_SHARP_DOWNLOAD} = false ]; then
14-
node scripts/download_sharp.js ${ARCH} ${OUT}
15-
else
16-
echo "Skipping sharp download"
17-
fi
18-
1912
mkdir -p dist
2013
node scripts/pkg.js ${ARCH} ${OUT}
2114
if [ $? != 0 ]; then

scripts/pkg.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@ const outputNodeModules = `${outputPath}/node_modules`
3434
childProcess.execSync(`"./node_modules/.bin/pkg" -t node14-${platform}-${arch} . --out-path ${outputPath} --no-native-build`, {stdio: 'inherit'});
3535

3636
childProcess.execSync(`rm -rf ${outputNodeModules}`)
37-
fs.mkdirSync(`${outputNodeModules}/sharp`, {recursive: true})
38-
childProcess.execSync(`cp -RP ./node_modules/sharp/build ${outputNodeModules}/sharp && cp -RP ./node_modules/sharp/vendor ${outputNodeModules}/sharp`)

src/browser/browser.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as chokidar from 'chokidar';
55
import * as path from 'path';
66
import * as fs from 'fs';
77
import * as promClient from 'prom-client';
8-
import * as sharp from 'sharp';
8+
import * as Jimp from 'jimp';
99
import { Logger } from '../logger';
1010
import { RenderingConfig } from '../config';
1111
import { ImageRenderOptions, RenderOptions } from '../types';
@@ -360,15 +360,18 @@ export class Browser {
360360
const scaled = `${options.filePath}_${Date.now()}_scaled.png`;
361361
const w = +options.width / options.scaleImage;
362362
const h = +options.height / options.scaleImage;
363-
await sharp(options.filePath)
364-
.resize(w, h, { fit: 'inside' })
365-
// .toFormat('webp', {
366-
// quality: 70, // 80 is default
367-
// })
368-
.toFile(scaled);
369-
370-
// overwrite the original image with the scaled value
371-
fs.renameSync(scaled, options.filePath);
363+
364+
await this.withTimingMetrics(async () => {
365+
const file = await Jimp.read(options.filePath);
366+
await file
367+
.resize(w, h)
368+
// .toFormat('webp', {
369+
// quality: 70, // 80 is default
370+
// })
371+
.writeAsync(scaled);
372+
373+
fs.renameSync(scaled, options.filePath);
374+
}, 'imageResize');
372375
}
373376

374377
return { filePath: options.filePath };

0 commit comments

Comments
 (0)