mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
Migrate from sharp to jimp
This avoids native/binary problems like #131 and #115 at the expense of a bit of performance. Fixes #131 Fixes #115
This commit is contained in:
parent
a68bdba4b5
commit
dcac5d8c44
4 changed files with 499 additions and 393 deletions
|
|
@ -50,12 +50,12 @@
|
|||
"@std/path": "jsr:@std/path@1.1.2",
|
||||
|
||||
"chart.js": "npm:chart.js@4.5.0",
|
||||
"jimp": "npm:jimp@1.6.0",
|
||||
"mrmime": "npm:mrmime@2.0.1",
|
||||
"nodemailer": "npm:nodemailer@7.0.6",
|
||||
"openid-client": "npm:openid-client@6.8.0",
|
||||
"otpauth": "npm:otpauth@9.4.1",
|
||||
"preact": "npm:preact@10.27.2",
|
||||
"sharp": "npm:sharp@0.34.4",
|
||||
"tailwindcss": "npm:tailwindcss@3.4.17",
|
||||
"tailwindcss/": "npm:/tailwindcss@3.4.17/",
|
||||
"tailwindcss/plugin": "npm:/tailwindcss@3.4.17/plugin.js",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
services:
|
||||
website:
|
||||
image: ghcr.io/bewcloud/bewcloud:v3.0.2
|
||||
image: ghcr.io/bewcloud/bewcloud:v3.1.0
|
||||
restart: always
|
||||
ports:
|
||||
- 127.0.0.1:8000:8000
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Handlers } from 'fresh/server.ts';
|
||||
import sharp from 'sharp';
|
||||
import { Jimp } from 'jimp';
|
||||
|
||||
import { FreshContextState } from '/lib/types.ts';
|
||||
import { FileModel } from '/lib/models/files.ts';
|
||||
|
|
@ -59,14 +59,16 @@ export const handler: Handlers<Data, FreshContextState> = {
|
|||
}
|
||||
|
||||
try {
|
||||
const image = sharp(fileResult.contents! as unknown as ArrayBuffer).resize({
|
||||
width,
|
||||
height,
|
||||
fit: 'cover',
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
}).png();
|
||||
const image = await Jimp.read(
|
||||
fileResult.contents!.buffer.slice(
|
||||
fileResult.contents!.byteOffset,
|
||||
fileResult.contents!.byteLength + fileResult.contents!.byteOffset,
|
||||
) as ArrayBuffer,
|
||||
);
|
||||
|
||||
const resizedImageContents = await image.toBuffer();
|
||||
image.scaleToFit({ w: width, h: height });
|
||||
|
||||
const resizedImageContents = await image.getBuffer(fileResult.contentType! as 'image/jpeg' | 'image/png');
|
||||
|
||||
return new Response(Uint8Array.from(resizedImageContents), {
|
||||
status: 200,
|
||||
|
|
|
|||
Loading…
Reference in a new issue