diff --git a/packages/integrations/image/src/loaders/squoosh.ts b/packages/integrations/image/src/loaders/squoosh.ts index 428ae4e34..c1cb815a5 100644 --- a/packages/integrations/image/src/loaders/squoosh.ts +++ b/packages/integrations/image/src/loaders/squoosh.ts @@ -111,7 +111,7 @@ class SquooshService extends BaseSSRService { const data = await processBuffer(inputBuffer, operations, transform.format, transform.quality || 100); return { - data, + data: Buffer.from(data), format: transform.format } } diff --git a/packages/integrations/image/src/vendor/squoosh/image-pool.ts b/packages/integrations/image/src/vendor/squoosh/image-pool.ts index 440dd1a5b..f888f00c9 100644 --- a/packages/integrations/image/src/vendor/squoosh/image-pool.ts +++ b/packages/integrations/image/src/vendor/squoosh/image-pool.ts @@ -89,7 +89,7 @@ export async function processBuffer( operations: Operation[], encoding: OutputFormat, quality: number -): Promise { +): Promise { // @ts-ignore const worker = await getWorker() @@ -116,25 +116,29 @@ export async function processBuffer( switch (encoding) { case 'avif': - return await worker.dispatchJob({ operation: 'encodeavif', imageData, quality: quality || 100 }) as Buffer; + return await worker.dispatchJob({ + operation: 'encodeavif', + imageData, + quality: quality || 100 + }) as Uint8Array; case 'jpeg': case 'jpg': return await worker.dispatchJob({ operation: 'encodejpeg', imageData, quality: quality || 100, - }) as Buffer; + }) as Uint8Array; case 'png': return await worker.dispatchJob({ operation: 'encodepng', imageData, - }) as Buffer; + }) as Uint8Array; case 'webp': return await worker.dispatchJob({ operation: 'encodejpeg', imageData, quality: quality || 100, - }) as Buffer; + }) as Uint8Array; default: throw Error(`Unsupported encoding format`) } diff --git a/packages/integrations/image/src/vendor/squoosh/impl.ts b/packages/integrations/image/src/vendor/squoosh/impl.ts index c0fd26843..722336807 100644 --- a/packages/integrations/image/src/vendor/squoosh/impl.ts +++ b/packages/integrations/image/src/vendor/squoosh/impl.ts @@ -72,7 +72,7 @@ export async function resize({ image, width, height }: ResizeOpts) { export async function encodeJpeg( image: ImageData, { quality }: { quality: number } -): Promise { +): Promise { image = ImageData.from(image) const e = supportedFormats['mozjpeg'] @@ -82,13 +82,13 @@ export async function encodeJpeg( ...e.defaultEncoderOptions, quality, }) - return Buffer.from(r) + return r } export async function encodeWebp( image: ImageData, { quality }: { quality: number } -): Promise { +): Promise { image = ImageData.from(image) const e = supportedFormats['webp'] @@ -98,13 +98,13 @@ export async function encodeWebp( ...e.defaultEncoderOptions, quality, }) - return Buffer.from(r) + return r } export async function encodeAvif( image: ImageData, { quality }: { quality: number } -): Promise { +): Promise { image = ImageData.from(image) const e = supportedFormats['avif'] @@ -117,12 +117,12 @@ export async function encodeAvif( // so a lower value yields higher quality (0 to 100). cqLevel: quality === 0 ? val : Math.round(val - (quality / 100) * val), }) - return Buffer.from(r) + return r } export async function encodePng( image: ImageData -): Promise { +): Promise { image = ImageData.from(image) const e = supportedFormats['oxipng'] @@ -131,5 +131,5 @@ export async function encodePng( const r = await m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, }) - return Buffer.from(r) + return r }