jimp-test
This commit is contained in:
parent
22deb24fa2
commit
a0c64bdaa8
@ -1,6 +1,5 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'
|
import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
|
||||||
import sharp from 'sharp'
|
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { Jimp } from 'jimp'
|
import { Jimp } from 'jimp'
|
||||||
|
|
||||||
@ -25,8 +24,6 @@ const checkArea = (obj) => {
|
|||||||
|
|
||||||
const cropImage = async (Key, width, height, left, top) => {
|
const cropImage = async (Key, width, height, left, top) => {
|
||||||
try {
|
try {
|
||||||
const checkResult = checkArea({ width, height, left, top })
|
|
||||||
|
|
||||||
// Get the image from S3
|
// Get the image from S3
|
||||||
const { Body } = await s3.send(
|
const { Body } = await s3.send(
|
||||||
new GetObjectCommand({
|
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 })
|
image.autocrop({ tolerance: 0.0002, leaveBorder: 10 })
|
||||||
const editedBuffer = await image.getBuffer('image/png')
|
return await image.getBuffer('image/png')
|
||||||
|
|
||||||
return editedBuffer
|
|
||||||
|
|
||||||
// Convert stream to buffer
|
// Convert stream to buffer
|
||||||
// const chunks = []
|
// const chunks = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user