mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-28 03:40:25 +01:00
fix
This commit is contained in:
parent
d5ca458c40
commit
d2b2422697
1 changed files with 46 additions and 33 deletions
|
@ -42,6 +42,19 @@ export function applyWatermark(img: string | Blob, el: HTMLCanvasElement, config
|
|||
watermark.onload = () => {
|
||||
const width = config.width || watermark.width;
|
||||
const height = config.height || watermark.height;
|
||||
ctx.globalAlpha = config.opacity;
|
||||
if (config.repeat !== false) {
|
||||
const resizedWatermark = document.createElement('canvas');
|
||||
resizedWatermark.width = width;
|
||||
resizedWatermark.height = height;
|
||||
const resizedCtx = resizedWatermark.getContext('2d')!;
|
||||
resizedCtx.drawImage(watermark, 0, 0, width, height);
|
||||
const pattern = ctx.createPattern(resizedWatermark, config.repeat === true ? 'repeat' : `repeat-${config.repeat}`);
|
||||
if (pattern) {
|
||||
ctx.fillStyle = pattern;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
} else {
|
||||
const x = (() => {
|
||||
switch (config.anchor) {
|
||||
case 'center':
|
||||
|
@ -74,8 +87,8 @@ export function applyWatermark(img: string | Blob, el: HTMLCanvasElement, config
|
|||
return canvas.height - height;
|
||||
}
|
||||
})();
|
||||
ctx.globalAlpha = config.opacity;
|
||||
ctx.drawImage(watermark, x, y, width, height);
|
||||
}
|
||||
};
|
||||
watermark.src = config.fileUrl;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue