test
test
This commit is contained in:
parent
5c1c50bd46
commit
63f12021e4
@ -26,6 +26,7 @@
|
|||||||
"framer-motion": "^11.2.13",
|
"framer-motion": "^11.2.13",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"iron-session": "^8.0.2",
|
"iron-session": "^8.0.2",
|
||||||
|
"jimp": "^1.6.0",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"mathjs": "^13.0.2",
|
"mathjs": "^13.0.2",
|
||||||
"mssql": "^11.0.1",
|
"mssql": "^11.0.1",
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import { NextResponse } from 'next/server'
|
|||||||
import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'
|
import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'
|
||||||
import sharp from 'sharp'
|
import sharp from 'sharp'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
import { Jimp } from 'jimp'
|
||||||
|
|
||||||
const Bucket = process.env.AMPLIFY_BUCKET
|
const Bucket = process.env.AMPLIFY_BUCKET
|
||||||
const s3 = new S3Client({
|
const s3 = new S3Client({
|
||||||
region: process.env.AWS_REGION,
|
region: process.env.AWS_REGION,
|
||||||
@ -33,27 +35,39 @@ const cropImage = async (Key, width, height, left, top) => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const image = await Jimp.read(Body)
|
||||||
|
image.autocrop({ tolerance: 0.0002, leaveBorder: 10 })
|
||||||
|
const editedBuffer = await image.getBufferAsync(Jimp.MIME_PNG)
|
||||||
|
|
||||||
|
return editedBuffer
|
||||||
|
|
||||||
// Convert stream to buffer
|
// Convert stream to buffer
|
||||||
const chunks = []
|
// const chunks = []
|
||||||
for await (const chunk of Body) {
|
// for await (const chunk of Body) {
|
||||||
chunks.push(chunk)
|
// chunks.push(chunk)
|
||||||
}
|
// }
|
||||||
const imageBuffer = Buffer.concat(chunks)
|
// const imageBuffer = Buffer.concat(chunks)
|
||||||
|
|
||||||
|
// const image = await Jimp.read(Body)
|
||||||
|
|
||||||
|
// if (!checkResult) {
|
||||||
|
// processedImage = await image.toBuffer()
|
||||||
|
// }
|
||||||
|
|
||||||
let processedImage
|
let processedImage
|
||||||
if (!checkResult) {
|
// if (!checkResult) {
|
||||||
processedImage = await sharp(imageBuffer).toBuffer()
|
// processedImage = await sharp(imageBuffer).toBuffer()
|
||||||
} else {
|
// } else {
|
||||||
processedImage = await sharp(imageBuffer)
|
// processedImage = await sharp(imageBuffer)
|
||||||
.extract({
|
// .extract({
|
||||||
width: parseInt(width),
|
// width: parseInt(width),
|
||||||
height: parseInt(height),
|
// height: parseInt(height),
|
||||||
left: parseInt(left),
|
// left: parseInt(left),
|
||||||
top: parseInt(top),
|
// top: parseInt(top),
|
||||||
})
|
// })
|
||||||
.png()
|
// .png()
|
||||||
.toBuffer()
|
// .toBuffer()
|
||||||
}
|
// }
|
||||||
return processedImage
|
return processedImage
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error processing image:', error)
|
console.error('Error processing image:', error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user