mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 08:12:04 +02:00
Don't allow skinny images in meme-gen
This commit is contained in:
@@ -56,6 +56,7 @@ module.exports = class MemeGenCommand extends Command {
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'top';
|
||||
const topLines = await wrapText(ctx, top, base.width - 10);
|
||||
if (!topLines) return msg.reply('There\'s not enough width to make a meme with this image.');
|
||||
for (let i = 0; i < topLines.length; i++) {
|
||||
const textHeight = (i * fontSize) + (i * 10);
|
||||
ctx.strokeStyle = 'black';
|
||||
@@ -65,6 +66,7 @@ module.exports = class MemeGenCommand extends Command {
|
||||
ctx.fillText(topLines[i], base.width / 2, textHeight);
|
||||
}
|
||||
const bottomLines = await wrapText(ctx, bottom, base.width - 10);
|
||||
if (!bottomLines) return msg.reply('There\'s not enough width to make a meme with this image.');
|
||||
ctx.textBaseline = 'bottom';
|
||||
const initial = base.height - ((bottomLines.length - 1) * fontSize) - ((bottomLines.length - 1) * 10);
|
||||
for (let i = 0; i < bottomLines.length; i++) {
|
||||
|
||||
@@ -61,6 +61,7 @@ module.exports = class NikeAdCommand extends Command {
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.textAlign = 'center';
|
||||
const lines = await wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width - 20);
|
||||
if (!lines) return msg.reply('There\'s not enough width to make a Nike ad with this image.');
|
||||
const initial = data.height / 2;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const textHeight = initial + (i * fontSize) + (i * 10);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "101.1.0",
|
||||
"version": "101.1.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -99,6 +99,7 @@ module.exports = class CanvasUtil {
|
||||
static wrapText(ctx, text, maxWidth) {
|
||||
return new Promise(resolve => {
|
||||
if (ctx.measureText(text).width < maxWidth) return resolve([text]);
|
||||
if (ctx.measureText('W').width > maxWidth) return resolve(null);
|
||||
const words = text.split(' ');
|
||||
const lines = [];
|
||||
let line = '';
|
||||
|
||||
Reference in New Issue
Block a user