v25.8.7
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://openfontlicense.org
|
||||
Binary file not shown.
Binary file not shown.
+32
-39
@@ -1,8 +1,13 @@
|
||||
import { createCanvas, loadImage, registerFont } from "canvas";
|
||||
import { writeFileSync } from "fs";
|
||||
import sharp from "sharp";
|
||||
import { MiQOptions } from "./miq";
|
||||
|
||||
// フォント読み込み
|
||||
registerFont("miq/fonts/MPLUS.ttf", {
|
||||
family: "M PLUS Rounded 1c",
|
||||
weight: "400",
|
||||
});
|
||||
|
||||
function maxLengthCut(
|
||||
text: string,
|
||||
maxLength: number,
|
||||
@@ -18,7 +23,7 @@ function maxLengthCut(
|
||||
function autoLineBreak(
|
||||
text: string,
|
||||
maxWidth: number,
|
||||
font: string = "48px Noto Sans JP"
|
||||
font: string = '48px "M PLUS Rounded 1c"'
|
||||
): string {
|
||||
const ctx = createCanvas(maxWidth, 100).getContext("2d");
|
||||
ctx.font = font;
|
||||
@@ -52,18 +57,23 @@ function autoLineBreak(
|
||||
|
||||
function textReplace(
|
||||
text: string,
|
||||
maxWidth: number
|
||||
maxWidth: number,
|
||||
font?: string
|
||||
) {
|
||||
// 改行削除
|
||||
text = text.replaceAll("\n", "");
|
||||
text = text.replaceAll("\r", "");
|
||||
// 自動改行
|
||||
text = autoLineBreak(text, maxWidth, font);
|
||||
// 100文字以上を省略
|
||||
text = maxLengthCut(text, 100);
|
||||
text = autoLineBreak(text, maxWidth);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
async function iconReplace(
|
||||
color: boolean,
|
||||
iconURL: string,
|
||||
iconURL: string
|
||||
) {
|
||||
let result = "";
|
||||
|
||||
@@ -102,9 +112,6 @@ export default async function MiQ({
|
||||
userName,
|
||||
userID,
|
||||
}: MiQOptions) {
|
||||
// フォント読み込み
|
||||
registerFont("miq/fonts/NotoSansJP.ttf", { family: "Noto Sans JP" });
|
||||
|
||||
// 初期化
|
||||
const canvas = createCanvas(1200, 630);
|
||||
const ctx = canvas.getContext("2d");
|
||||
@@ -122,26 +129,26 @@ export default async function MiQ({
|
||||
ctx.drawImage(iconImg, 0, 0, iconSize, iconSize);
|
||||
|
||||
// ユーザー名描画
|
||||
ctx.font = "38px Noto Sans JP";
|
||||
ctx.font = '38px "M PLUS Rounded 1c"';
|
||||
ctx.fillStyle = "white";
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
let x = 910;
|
||||
let y = 480;
|
||||
ctx.fillText(`- ${userName}`, x, y, canvas.width-x);
|
||||
ctx.fillText(`- ${userName}`, x, y, canvas.width-iconSize);
|
||||
|
||||
// ユーザーID描画
|
||||
ctx.font = "28px Noto Sans JP";
|
||||
ctx.fillStyle = "#3c3c3c";
|
||||
ctx.fillText(`@${userID}`, x, y+50, canvas.width-x);
|
||||
ctx.font = '28px "M PLUS Rounded 1c"';
|
||||
ctx.fillStyle = "#b4b4b4";
|
||||
ctx.fillText(`@${userID}`, x, y+50, canvas.width-iconSize);
|
||||
|
||||
// 本文描画
|
||||
const maxWidth = canvas.width - iconSize;
|
||||
text = textReplace(text, maxWidth);
|
||||
ctx.font = "48px Noto Sans JP";
|
||||
ctx.font = '48px "M PLUS Rounded 1c"';
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillStyle = "white";
|
||||
text = textReplace(text, maxWidth, ctx.font);
|
||||
ctx.fillText(text, x, 80);
|
||||
|
||||
// フェード描画
|
||||
@@ -153,29 +160,15 @@ export default async function MiQ({
|
||||
ctx.fillRect(0, 0, iconSize, canvas.height);
|
||||
|
||||
// 返答
|
||||
if (type === "Buffer") {
|
||||
return canvas.toBuffer();
|
||||
} else if (type === "Base64Data") {
|
||||
return canvas.toDataURL()
|
||||
.replace("data:image/png;base64,", "");
|
||||
} else if (type === "Base64URL") {
|
||||
return canvas.toDataURL();
|
||||
} else {
|
||||
return "Error: The type property is invalid.";
|
||||
switch (type) {
|
||||
case "Buffer":
|
||||
return canvas.toBuffer();
|
||||
case "Base64Data":
|
||||
return canvas.toDataURL()
|
||||
.replace("data:image/png;base64,", "");
|
||||
case "Base64URL":
|
||||
return canvas.toDataURL();
|
||||
default:
|
||||
return "Error: The type property is invalid.";
|
||||
}
|
||||
}
|
||||
|
||||
/*(async () => {
|
||||
writeFileSync(
|
||||
"miq/a.png",
|
||||
await MiQ({
|
||||
type: "Buffer",
|
||||
color: false,
|
||||
text: "テスト",
|
||||
iconURL: "https://media.uwuzu.net/uwuzu-net/files/3ov7dghkn7.webp",
|
||||
userName: "Last2014",
|
||||
userID: "last2014",
|
||||
}),
|
||||
"utf-8"
|
||||
);
|
||||
})()*/
|
||||
|
||||
Reference in New Issue
Block a user