Skip to content

Commit 52f7dc7

Browse files
authored
Merge pull request #126 from wchaws/dev2
Dev2
2 parents 556b808 + e8f663e commit 52f7dc7

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

source/new-image-handler/src/processor/image/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class ImageProcessor implements IProcessor {
6767
act.beforeNewContext.bind(act)(ctx, params);
6868
}
6969
const { buffer, headers } = await bufferStore.get(uri);
70-
const image = sharp(buffer, { animated: ctx.features[Features.ReadAllAnimatedFrames] });
70+
const image = sharp(buffer, { failOnError: false, animated: ctx.features[Features.ReadAllAnimatedFrames] });
7171
const metadata = await image.metadata();
7272

7373
if ('gif' === metadata.format) {

source/new-image-handler/src/processor/image/watermark.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class WatermarkAction extends BaseImageAction {
5555
}
5656

5757
public validate(params: string[]): ReadOnly<WatermarkOpts> {
58-
let opt: WatermarkOpts = {
58+
const opt: WatermarkOpts = {
5959
text: '',
6060
t: 100,
6161
g: 'southeast',
@@ -187,7 +187,7 @@ export class WatermarkAction extends BaseImageAction {
187187

188188
async textWaterMark(ctx: IImageContext, opt: WatermarkOpts): Promise<void> {
189189
const textOpt = this.calculateTextSize(opt.text, opt.size);
190-
const svg = this.textSvgStr(opt, textOpt);
190+
const svg = this.textSvgStr(opt, textOpt, true, opt.shadow / 100);
191191
const svgBytes = Buffer.from(svg);
192192
const metadata = await ctx.image.metadata();
193193
if (0 < opt.rotate) {
@@ -265,7 +265,7 @@ export class WatermarkAction extends BaseImageAction {
265265
async mixedWaterMark(ctx: IImageContext, opt: WatermarkOpts): Promise<void> {
266266
const bs = ctx.bufferStore;
267267
const textOpt = this.calculateTextSize(opt.text, opt.size);
268-
const svg = this.textSvgStr(opt, textOpt, false);
268+
const svg = this.textSvgStr(opt, textOpt, false, opt.shadow / 100);
269269
const svgBytes = Buffer.from(svg);
270270

271271
const watermarkImgBuffer = (await bs.get(opt.image)).buffer;
@@ -342,13 +342,16 @@ export class WatermarkAction extends BaseImageAction {
342342
height: Math.round(fontSize * 1.2),
343343
};
344344
}
345-
textSvgStr(opt: WatermarkOpts, textOpt: WatermarkTextOpts, applyOpacity: boolean = true): string {
345+
textSvgStr(opt: WatermarkOpts, textOpt: WatermarkTextOpts, applyOpacity: boolean = true, shadow: number = 0): string {
346346
const xOffset = Math.round(textOpt.width / 2);
347347
const yOffset = Math.round(textOpt.height * 0.8);
348348
const color = `#${opt.color}`;
349349
const opacity = applyOpacity ? opt.t / 100 : 1;
350+
// https://gitlab.gnome.org/GNOME/librsvg/-/blob/main/FEATURES.md
351+
// https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/529
352+
// https://github.com/lovell/sharp/issues/1490#issuecomment-1162760143
350353
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${textOpt.width} ${textOpt.height}" text-anchor="middle">
351-
<text font-size='${opt.size}' x="${xOffset}" y="${yOffset}" fill="${color}" opacity="${opacity}" font-family="${opt.type}">${opt.text}</text>
354+
<text filter="drop-shadow(rgba(0,0,0,${shadow}) 2px 0px 2px)" font-size="${opt.size}" x="${xOffset}" y="${yOffset}" fill="${color}" opacity="${opacity}" font-family="${opt.type}">${opt.text}</text>
352355
</svg>`;
353356
return svg;
354357
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
# ./curl.sh urls.txt 2
3+
4+
URLS=$1
5+
N=${2:-2}
6+
7+
echo "request ${N} urls in parallel"
8+
printf "time_total(sec)\thttp_code\tsize_download(bytes)\turl\n"
9+
cat ${URLS} | xargs -P ${N} -I {} curl -s "{}" -o /dev/null -w "%{time_total}\t%{http_code}\t%{size_download}\t{}\n"

0 commit comments

Comments
 (0)