From a0c64bdaa8f0b0e94e619752dae3747342727864 Mon Sep 17 00:00:00 2001 From: "hyojun.choi" Date: Thu, 5 Jun 2025 17:49:37 +0900 Subject: [PATCH] jimp-test --- src/app/api/image/canvas/route.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/api/image/canvas/route.js b/src/app/api/image/canvas/route.js index 2afb6b8f..2a20da92 100644 --- a/src/app/api/image/canvas/route.js +++ b/src/app/api/image/canvas/route.js @@ -1,6 +1,5 @@ import { NextResponse } from 'next/server' -import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3' -import sharp from 'sharp' +import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3' import { v4 as uuidv4 } from 'uuid' import { Jimp } from 'jimp' @@ -25,8 +24,6 @@ const checkArea = (obj) => { const cropImage = async (Key, width, height, left, top) => { try { - const checkResult = checkArea({ width, height, left, top }) - // Get the image from S3 const { Body } = await s3.send( new GetObjectCommand({ @@ -35,13 +32,16 @@ const cropImage = async (Key, width, height, left, top) => { }), ) - console.log(Body) + const chunks = [] + for await (const chunk of Body) { + chunks.push(chunk) + } + const buffer = Buffer.concat(chunks) + + const image = await Jimp.read(buffer) - const image = await Jimp.read(Body) image.autocrop({ tolerance: 0.0002, leaveBorder: 10 }) - const editedBuffer = await image.getBuffer('image/png') - - return editedBuffer + return await image.getBuffer('image/png') // Convert stream to buffer // const chunks = []