V 3.0.1 LaiTool V3.0.1-preview.3

This commit is contained in:
2024-08-08 16:24:47 +08:00
parent f3a25e9474
commit 36178fbe5d
40 changed files with 1545 additions and 581 deletions
+37 -22
View File
@@ -171,13 +171,13 @@ export function CompressImageToSize(base64: string, maxSizeInBytes: number): Pro
* 将选中的区域涂白,其他区域涂黑(这个颜色可以变)
* @param inputPath 输入的文件路径
* @param outputPath 输出的文件路径
* @param region 范围对象,包含x, y, width, height属性
* @param markColor 标记颜色,默认为色 { r: 255, g: 255, b: 255 }
* @param backColor 背景颜色,默认为色 { r: 0, g: 0, b: 0 }
* @param regions 范围对象,包含x, y, width, height属性
* @param markColor 标记颜色,默认为色 { r: 255, g: 255, b: 255 }
* @param backColor 背景颜色,默认为色 { r: 0, g: 0, b: 0 }
*/
export async function ProcessImage(inputPath: string,
outputPath: string,
region: { width: any; height: any; x: any; y: any },
regions: { width: any; height: any; x: any; y: any, imageWidth?: any, imageHeight?: any }[],
markColor: { r: number; g: number; b: number } = { r: 255, g: 255, b: 255 },
backColor: { r: number; g: number; b: number } = { r: 0, g: 0, b: 0 },
): Promise<void> {
@@ -188,7 +188,7 @@ export async function ProcessImage(inputPath: string,
// 获取图片的元数据
const { width, height } = await image.metadata();
// 创建一个新的空白图片,背景为白色
// 创建一个新的黑色图片,背景为白色
const whiteBackground = await sharp({
create: {
width,
@@ -198,27 +198,42 @@ export async function ProcessImage(inputPath: string,
}
}).png().toBuffer();
// 创建一个黑色的矩形
const blackRegion = await sharp({
create: {
width: region.width,
height: region.height,
channels: 3, // RGB channels
background: markColor // Black color
// 创建多个白色的矩形,并进行合成
const composites = await Promise.all(regions.map(async (region) => {
let rateW = undefined;
let rateY = undefined;
let rate = undefined;
if (region.imageWidth != null && region.imageHeight != null) {
rateY = height / region.imageHeight;
rateW = width / region.imageWidth;
rate = rateY;
}
if (rate == null) {
rate = 1;
}
}).png().toBuffer();
// 在白色背景上叠加黑色矩形
await sharp(whiteBackground)
.composite([
{
input: blackRegion,
left: region.x,
top: Math.floor(region.y)
const regionBuffer = await sharp({
create: {
width: Math.ceil(region.width * rate),
height: Math.ceil(region.height * rate),
channels: 3, // RGB channels
background: markColor // 标记颜色
}
])
.toFile(outputPath);
}).png().toBuffer();
return {
input: regionBuffer,
left: Math.ceil(region.x * rate),
top: Math.ceil(region.y * rate),
};
}));
// 在背景上叠加所有的矩形区域
await sharp(whiteBackground)
.composite(composites)
.toFile(outputPath);
} catch (err) {
throw err;
+7 -7
View File
@@ -2,17 +2,17 @@ let apiUrl = [
{
label: 'LAI API',
value: 'b44c6f24-59e4-4a71-b2c7-3df0c4e35e65',
gpt_url: 'https://laitool.net/v1/chat/completions',
gpt_url: 'https://api.laitool.cc/v1/chat/completions',
mj_url: {
imagine: 'https://laitool.net/mj/submit/imagine',
describe: 'https://laitool.net/mj/submit/describe',
update_file: 'https://laitool.net/mj/submit/upload-discord-images',
once_get_task: 'https://laitool.net/mj/task/${id}/fetch'
imagine: 'https://api.laitool.cc/mj/submit/imagine',
describe: 'https://api.laitool.cc/mj/submit/describe',
update_file: 'https://api.laitool.cc/mj/submit/upload-discord-images',
once_get_task: 'https://api.laitool.cc/mj/task/${id}/fetch'
},
d3_url: {
image: 'https://laitool.net/v1/images/generations'
image: 'https://api.laitool.cc/v1/images/generations'
},
buy_url: 'https://laitool.net/register?aff=Zmdu'
buy_url: 'https://api.laitool.cc/register?aff=Zmdu'
},
{
label: 'openai-hk',
+5 -3
View File
@@ -24,7 +24,8 @@ export class BookModel extends Realm.Object<BookModel> {
videoConfig: string | null // 合成视频设置
prefixPrompt: string | null // 前缀
suffixPrompt: string | null // 后缀
subtitlePosition: string | null
subtitlePosition: string | null // 字幕位置
watermarkPosition: string | null // 水印位置,一个json数组字符串
static schema: Realm.ObjectSchema = {
name: 'Book',
@@ -37,7 +38,7 @@ export class BookModel extends Realm.Object<BookModel> {
oldVideoPath: 'string?',
srtPath: 'string?',
audioPath: 'string?',
draftSrtStyle : 'string?',
draftSrtStyle: 'string?',
backgroundMusic: 'string?',
friendlyReminder: 'string?',
imageFolder: 'string?',
@@ -50,7 +51,8 @@ export class BookModel extends Realm.Object<BookModel> {
videoConfig: "string?",
prefixPrompt: "string?",
suffixPrompt: "string?",
subtitlePosition: 'string?'
subtitlePosition: 'string?',
watermarkPosition: "string?"
},
// 主键为_id
primaryKey: 'id'
+8 -1
View File
@@ -155,6 +155,13 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
newBookTask[i].subValue = '[]'
}
}
if (oldRealm.schemaVersion < 22) {
const oldBookTask = oldRealm.objects('Book')
const newBookTask = newRealm.objects('Book')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].watermarkPosition = '[]'
}
}
}
export class BaseRealmService extends BaseService {
@@ -196,7 +203,7 @@ export class BaseRealmService extends BaseService {
BookTaskDetailModel
],
path: this.dbpath,
schemaVersion: 21,
schemaVersion: 22,
migration: migration
}
this.realm = await Realm.open(config)
+1 -1
View File
@@ -277,7 +277,7 @@ export class BookService extends BaseRealmService {
* @param bookId 小说的ID
* @param bookData 要修改的小说数据
*/
async UpdateBookData(bookId: string, bookData) {
async UpdateBookData(bookId: string, bookData: Book.SelectBook) {
try {
if (bookId == null) {
throw new Error('修改小说数据失败,缺少小说ID')
+4 -2
View File
@@ -202,7 +202,8 @@ export const DEFINE_STRING = {
BASE64_TO_FILE: 'BASE64_TO_FILE',
PROCESS_IMAGE: 'PROCESS_IMAGE',
BATCH_PROCESS_IMAGE: 'BATCH_PROCESS_IMAGE',
BATCH_PROCESS_IMAGE_RESULT: 'BATCH_PROCESS_IMAGE_RESULT'
BATCH_PROCESS_IMAGE_RESULT: 'BATCH_PROCESS_IMAGE_RESULT',
PROCESS_IMAGE_WATERMASK_CHECK: "PROCESS_IMAGE_WATERMASK_CHECK"
},
BOOK: {
MAIN_DATA_RETURN: 'MAIN_DATA_RETURN', // 监听任务返回
@@ -291,6 +292,7 @@ export const DEFINE_STRING = {
},
DB: {
UPDATE_BOOK_TASK_DATA: "UPDATE_BOOK_TASK_DATA",
UPDATE_BOOK_TASK_DETAIL_DATA: "UPDATE_BOOK_TASK_DETAIL_DATA"
UPDATE_BOOK_TASK_DETAIL_DATA: "UPDATE_BOOK_TASK_DETAIL_DATA",
UPDATE_BOOK_DATA: "UPDATE_BOOK_DATA"
}
}
+12 -3
View File
@@ -64,21 +64,30 @@ export class TagDefine {
if (res.hasOwnProperty('character_tags')) {
res.character_tags.forEach((item) => {
if (item.show_image && item.show_image != '') {
item.show_image = path.join(define.image_path, item.show_image)
item.show_image = path.join(
define.image_path,
item.show_image + '?t=' + new Date().getTime()
)
}
})
}
if (res.hasOwnProperty('scene_tags')) {
res.scene_tags.forEach((item) => {
if (item.show_image && item.show_image != '') {
item.show_image = path.join(define.image_path, item.show_image)
item.show_image = path.join(
define.image_path,
item.show_image + '?t=' + new Date().getTime()
)
}
})
}
if (res.hasOwnProperty('style_tags')) {
res.style_tags.forEach((item) => {
if (item.show_image && item.show_image != '') {
item.show_image = path.join(define.image_path, item.show_image)
item.show_image = path.join(
define.image_path,
item.show_image + '?t=' + new Date().getTime()
)
}
})
}