Skip to content

Commit

Permalink
Revert "Experimental: /proxy下でのリサイズ処理に試験的にwasm-vipsを導入"
Browse files Browse the repository at this point in the history
This reverts commit 2b87d5c.
  • Loading branch information
nexryai committed Feb 3, 2025
1 parent 2b87d5c commit 2d1ee89
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
3 changes: 1 addition & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"typeorm": "0.3.20",
"ulid": "2.3.0",
"uuid": "11.0.5",
"wasm-vips": "0.0.11",
"web-push": "3.6.7",
"ws": "8.18.0",
"xev": "3.0.2"
Expand All @@ -113,7 +112,7 @@
"@types/bcryptjs": "2.4.6",
"@types/bull": "4.10.4",
"@types/cbor": "6.0.4",
"@types/co-body": "6.1.3",
"@types/co-body": "6.1.3",
"@types/escape-regexp": "0.0.3",
"@types/fluent-ffmpeg": "2.1.27",
"@types/js-yaml": "4.0.9",
Expand Down
37 changes: 2 additions & 35 deletions packages/backend/src/services/drive/image-processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import sharp from "sharp";
import Vips, { Image } from "wasm-vips";


export type IImage = {
data: Buffer;
Expand Down Expand Up @@ -40,39 +38,8 @@ export async function convertSharpToJpeg(sharp: sharp.Sharp, width: number, heig
* Convert to WebP
* with resize, remove metadata, resolve orientation, stop animation
*/
export async function convertToWebp(path: string, width: number, height: number, quality = 75): Promise<IImage> {
const vips = await Vips();
const image = vips.Image.newFromFile(path);

return convertVipsToWebp(image, width, height, quality);
}

export async function convertVipsToWebp(image: Image, width: number, height: number, quality = 75): Promise<IImage> {
// Resize
const originalWidth = image.width;
const originalHeight = image.height;

const ratio = originalWidth / originalHeight;
const targetRatio = width / height;

const scale =
ratio > targetRatio ?
height < width ?
height / originalHeight : width / originalWidth
: 1;


const resized = image.resize(scale);
const encoded = resized.webpsaveBuffer({
Q: quality,
lossless: false,
});

return {
data: Buffer.from(encoded),
ext: "webp",
type: "image/webp",
} as IImage;
export async function convertToWebp(path: string, width: number, height: number, quality = 85): Promise<IImage> {
return convertSharpToWebp(await sharp(path), width, height, quality);
}

export async function convertSharpToWebp(sharp: sharp.Sharp, width: number, height: number, quality = 85): Promise<IImage> {
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5549,11 +5549,6 @@ w3c-xmlserializer@^5.0.0:
dependencies:
xml-name-validator "^5.0.0"

[email protected]:
version "0.0.11"
resolved "https://registry.yarnpkg.com/wasm-vips/-/wasm-vips-0.0.11.tgz#d147f54ef19c6f110135958acae6004968488950"
integrity sha512-bzFU7WcimMY4WeqnZk7whKVpSXxpagISXPJwsk2VHF4lgIN9rl4uUo5sF9x6jOlACuCH6ITZUJ7QPTYmy60NCQ==

[email protected]:
version "3.6.7"
resolved "https://registry.yarnpkg.com/web-push/-/web-push-3.6.7.tgz#5f5e645951153e37ef90a6ddea5c150ea0f709e1"
Expand Down

0 comments on commit 2d1ee89

Please sign in to comment.