mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
Fix
This commit is contained in:
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
|||||||
const { createCanvas, loadImage, registerFont } = require('canvas');
|
const { createCanvas, loadImage, registerFont } = require('canvas');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { wrapText } = require('../../util/Canvas');
|
||||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
|
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
|
||||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
|
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
|
||||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
|
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
|
||||||
@@ -19,8 +20,7 @@ module.exports = class MemeGenModernCommand extends Command {
|
|||||||
'create-modern-meme',
|
'create-modern-meme',
|
||||||
'm-meme-gen',
|
'm-meme-gen',
|
||||||
'm-meme-generator',
|
'm-meme-generator',
|
||||||
'create-m-meme',
|
'create-m-meme'
|
||||||
|
|
||||||
],
|
],
|
||||||
group: 'edit-meme',
|
group: 'edit-meme',
|
||||||
memberName: 'meme-gen-modern',
|
memberName: 'meme-gen-modern',
|
||||||
@@ -58,14 +58,12 @@ module.exports = class MemeGenModernCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const { body } = await request.get(image);
|
const { body } = await request.get(image);
|
||||||
const base = await loadImage(body);
|
const base = await loadImage(body);
|
||||||
const scaleH = plate.width / base.width;
|
const canvas = createCanvas(body.width, body.height);
|
||||||
const height = Math.round(base.height * scaleH);
|
|
||||||
const canvas = createCanvas(plate.width, plate.height + height);
|
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.font = '23px Noto';
|
ctx.font = '23px Noto';
|
||||||
ctx.fillStyle = 'black';
|
ctx.fillStyle = 'black';
|
||||||
ctx.textBaseline = 'top';
|
ctx.textBaseline = 'top';
|
||||||
const lines = await wrapText(ctx, text, plate.width - 10);
|
const lines = await wrapText(ctx, text, base.width - 10);
|
||||||
const linesLen = (23 * lines.length) + (23 * (text.split('\n').length - 1)) + (9 * lines.length);
|
const linesLen = (23 * lines.length) + (23 * (text.split('\n').length - 1)) + (9 * lines.length);
|
||||||
canvas.height += linesLen;
|
canvas.height += linesLen;
|
||||||
ctx.fillStyle = 'white';
|
ctx.fillStyle = 'white';
|
||||||
|
|||||||
Reference in New Issue
Block a user