v25.8.5@uwuzu1.6.4

This commit is contained in:
2025-08-25 06:11:36 +09:00
parent db719b8312
commit bbf2d66b57
11 changed files with 353 additions and 7 deletions
+93
View File
@@ -0,0 +1,93 @@
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
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
+134
View File
@@ -0,0 +1,134 @@
import { createCanvas, loadImage, registerFont } from "canvas";
import { writeFileSync } from "fs";
import sharp from "sharp";
import { MiQOptions } from "./miq";
function textReplace(
text: string
) {
let result = "";
// 改行削除
text = text.replaceAll("\n", "");
// 10文字/1回で改行を追加
let maxLength = 10;
if (text.length > maxLength) {
for (let i = 0; i < text.length; i += maxLength) {
result += text.substring(i, i + maxLength) + "\n";
}
result = result.trimEnd();
}
// 80文字以上は「...」で省略
maxLength = 80;
if (result.length > maxLength) {
result = result.substring(0, maxLength)
+ "...";
}
return result;
}
async function iconReplace(
color: boolean,
iconURL: string,
) {
let result = "";
const buffer = await(await fetch(iconURL, {
method: "GET",
cache: "no-store",
})).arrayBuffer();
if (color) {
const img = await sharp(Buffer.from(buffer))
.png()
.toBuffer();
result = `data:image/png;base64,${img.toString("base64")}`;
} else {
const img = await sharp(Buffer.from(buffer))
.png()
.grayscale()
.toBuffer();
result = `data:image/png;base64,${img.toString("base64")}`;
}
return result;
}
/**
* A function to generate
* Make it a quote on Node.js.
*/
export default async function MiQ({
type,
color,
text,
iconURL,
userName,
userID,
}: MiQOptions) {
// フォント読み込み
registerFont("miq/fonts/NotoSansJP.ttf", { family: "Noto Sans JP" });
// 初期化
const canvas = createCanvas(1200, 630);
const ctx = canvas.getContext("2d");
// 背景描画
ctx.fillStyle = "black";
ctx.fillRect(0, 0, canvas.width, canvas.height);
// アイコン描画
const iconImg = await loadImage(await iconReplace(
color,
iconURL,
));
const iconSize = canvas.height;
ctx.drawImage(iconImg, 0, 0, iconSize, iconSize);
// ユーザー名描画
ctx.font = "38px Noto Sans JP";
ctx.fillStyle = "white";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
let x = 670;
let y = 480;
ctx.fillText("-", x, y);
ctx.fillText(userName, x+40, y, canvas.width-(x+40));
// ユーザーID描画
ctx.font = "28px Noto Sans JP";
ctx.fillStyle = "#3c3c3c";
ctx.fillText(`@${userID}`, x+120, y+50, canvas.width-(x+120));
// 本文描画
ctx.font = "48px Noto Sans JP";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "white";
text = textReplace(text);
x = 870;
y = 30;
ctx.fillText(text, x, y+50);
// フェード描画
const fadeColor = "black";
const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
gradient.addColorStop(0, "rgba(0, 0, 0, 0)");
gradient.addColorStop(0.5, fadeColor);
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, iconSize, canvas.height);
// 返答
if (type === "Buffer") {
return canvas.toBuffer();
} else if (type === "Base64") {
return canvas.toDataURL();
} else {
return "Error: The type property is invalid.";
}
}
+12
View File
@@ -0,0 +1,12 @@
type MiQType =
"Buffer" |
"Base64"
export interface MiQOptions {
type: MiQType;
color: boolean;
text: string;
iconURL: string;
userName: string;
userID: string;
}