mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
scale height too
This commit is contained in:
@@ -51,15 +51,18 @@ module.exports = class DemotivationalPosterCommand extends Command {
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
const ratio = data.width / data.height;
|
||||
const width = Math.min(Math.round(402 / ratio), 602);
|
||||
const widthHigher = width >= height;
|
||||
const width = widthHigher ? 602 : Math.min(Math.round(402 / ratio), 602);
|
||||
const height = widthHigher ? Math.min(Math.round(602 * ratio), 402) : 402;
|
||||
const x = (canvas.width / 2) - (width / 2);
|
||||
const y = (402 / 2) - (height / 2);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x - 4, 40, width + 8, 410);
|
||||
ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(x - 2, 42, width + 4, 406);
|
||||
ctx.fillRect(x - 2, y - 2, width + 4, height + 4);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x, 44, width, 402);
|
||||
ctx.drawImage(data, x, 44, width, 402);
|
||||
ctx.fillRect(x, y, width, height);
|
||||
ctx.drawImage(data, x, y, width, height);
|
||||
ctx.textAlign = 'center';
|
||||
ctx.font = '60px Noto';
|
||||
ctx.fillStyle = 'aquamarine';
|
||||
|
||||
Reference in New Issue
Block a user