mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Farewell, stupid sharp. Hello jimp (thx CncAnon)
This commit is contained in:
1363
package-lock.json
generated
1363
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,14 +5,14 @@
|
|||||||
"csrf-csrf": "^2.2.3",
|
"csrf-csrf": "^2.2.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"ipaddr.js": "^2.0.1",
|
"ipaddr.js": "^2.0.1",
|
||||||
|
"jimp": "^0.22.7",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"node-rest-client": "^3.1.1",
|
"node-rest-client": "^3.1.1",
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.0",
|
||||||
"png-chunk-text": "^1.0.0",
|
"png-chunk-text": "^1.0.0",
|
||||||
"png-chunks-encode": "^1.0.0",
|
"png-chunks-encode": "^1.0.0",
|
||||||
"png-chunks-extract": "^1.0.0",
|
"png-chunks-extract": "^1.0.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2"
|
||||||
"sharp": "^0.31.3"
|
|
||||||
},
|
},
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.8",
|
"version": "1.2.8",
|
||||||
@@ -25,8 +25,6 @@
|
|||||||
},
|
},
|
||||||
"pkg": {
|
"pkg": {
|
||||||
"assets": [
|
"assets": [
|
||||||
"node_modules/sharp/build/Release/**/*",
|
|
||||||
"node_modules/sharp/vendor/lib/**/*",
|
|
||||||
"node_modules/open/xdg-open/",
|
"node_modules/open/xdg-open/",
|
||||||
"public",
|
"public",
|
||||||
"uploads"
|
"uploads"
|
||||||
|
@@ -759,9 +759,6 @@
|
|||||||
|
|
||||||
<form id="form_character_search_form" action="javascript:void(null);">
|
<form id="form_character_search_form" action="javascript:void(null);">
|
||||||
<input id="character_search_bar" class="text_pole" type="search" placeholder="Search here..." />
|
<input id="character_search_bar" class="text_pole" type="search" placeholder="Search here..." />
|
||||||
<div id="characloud_url" class="menu_button" title="Find more characters on CharaCloud (coming soon)">
|
|
||||||
<img src="img/cloud_logo.png">
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
<div id="rm_print_characters_block"></div>
|
<div id="rm_print_characters_block"></div>
|
||||||
|
|
||||||
|
35
server.js
35
server.js
@@ -1,10 +1,10 @@
|
|||||||
var express = require('express');
|
const express = require('express');
|
||||||
var app = express();
|
const app = express();
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
const open = require('open');
|
const open = require('open');
|
||||||
|
|
||||||
var rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
const multer = require("multer");
|
const multer = require("multer");
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
//const PNG = require('pngjs').PNG;
|
//const PNG = require('pngjs').PNG;
|
||||||
@@ -12,8 +12,7 @@ const extract = require('png-chunks-extract');
|
|||||||
const encode = require('png-chunks-encode');
|
const encode = require('png-chunks-encode');
|
||||||
const PNGtext = require('png-chunk-text');
|
const PNGtext = require('png-chunk-text');
|
||||||
|
|
||||||
const sharp = require('sharp');
|
const jimp = require('jimp');
|
||||||
sharp.cache(false);
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const cookieParser = require('cookie-parser');
|
const cookieParser = require('cookie-parser');
|
||||||
@@ -625,25 +624,20 @@ app.post("/deletecharacter", urlencodedParser, function (request, response) {
|
|||||||
|
|
||||||
async function charaWrite(img_url, data, target_img, response = undefined, mes = 'ok') {
|
async function charaWrite(img_url, data, target_img, response = undefined, mes = 'ok') {
|
||||||
try {
|
try {
|
||||||
// Load the image in any format
|
// Read the image, resize, and save it as a PNG into the buffer
|
||||||
sharp.cache(false);
|
const rawImg = await jimp.read(img_url);
|
||||||
var image = await sharp(img_url).resize(400, 600).toFormat('png').toBuffer();// old 170 234
|
const image = await rawImg.resize(400, 600).getBufferAsync(jimp.MIME_PNG);
|
||||||
// Convert the image to PNG format
|
|
||||||
//const pngImage = image.toFormat('png');
|
|
||||||
|
|
||||||
// Resize the image to 100x100
|
|
||||||
//const resizedImage = pngImage.resize(100, 100);
|
|
||||||
|
|
||||||
// Get the chunks
|
// Get the chunks
|
||||||
var chunks = extract(image);
|
const chunks = extract(image);
|
||||||
var tEXtChunks = chunks.filter(chunk => chunk.create_date === 'tEXt');
|
const tEXtChunks = chunks.filter(chunk => chunk.create_date === 'tEXt');
|
||||||
|
|
||||||
// Remove all existing tEXt chunks
|
// Remove all existing tEXt chunks
|
||||||
for (var tEXtChunk of tEXtChunks) {
|
for (let tEXtChunk of tEXtChunks) {
|
||||||
chunks.splice(chunks.indexOf(tEXtChunk), 1);
|
chunks.splice(chunks.indexOf(tEXtChunk), 1);
|
||||||
}
|
}
|
||||||
// Add new chunks before the IEND chunk
|
// Add new chunks before the IEND chunk
|
||||||
var base64EncodedData = Buffer.from(data, 'utf8').toString('base64');
|
const base64EncodedData = Buffer.from(data, 'utf8').toString('base64');
|
||||||
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
|
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
|
||||||
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
|
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
|
||||||
|
|
||||||
@@ -662,7 +656,6 @@ async function charaWrite(img_url, data, target_img, response = undefined, mes =
|
|||||||
|
|
||||||
|
|
||||||
function charaRead(img_url) {
|
function charaRead(img_url) {
|
||||||
sharp.cache(false);
|
|
||||||
const buffer = fs.readFileSync(img_url);
|
const buffer = fs.readFileSync(img_url);
|
||||||
const chunks = extract(buffer);
|
const chunks = extract(buffer);
|
||||||
|
|
||||||
@@ -1378,7 +1371,9 @@ app.post('/uploaduseravatar', urlencodedParser, async (request, response) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const pathToUpload = path.join('./uploads/' + request.file.filename);
|
const pathToUpload = path.join('./uploads/' + request.file.filename);
|
||||||
const image = await sharp(pathToUpload).resize(400, 400).toFormat('png').toBuffer();
|
const rawImg = await jimp.read(pathToUpload);
|
||||||
|
const image = await rawImg.resize(400, 400).getBufferAsync(jimp.MIME_PNG);
|
||||||
|
|
||||||
const filename = `${Date.now()}.png`;
|
const filename = `${Date.now()}.png`;
|
||||||
const pathToNewFile = path.join(directories.avatars, filename);
|
const pathToNewFile = path.join(directories.avatars, filename);
|
||||||
fs.writeFileSync(pathToNewFile, image);
|
fs.writeFileSync(pathToNewFile, image);
|
||||||
|
Reference in New Issue
Block a user