Created
February 27, 2022 21:47
-
-
Save acorcutt/1fc4fcf2d110965604043e0edf11bef7 to your computer and use it in GitHub Desktop.
Testing sharp image merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sharp from 'sharp'; | |
export default async function handler(req, res) { | |
const { url, logo } = req.query || []; | |
const imgRes = await fetch(url); | |
const logoRes = await fetch(logo); | |
//return res.status(200).json({ url, status: imgRes.status }); | |
const imgBuffer = Buffer.from(await imgRes.arrayBuffer()); | |
const logoBuffer = Buffer.from(await logoRes.arrayBuffer()); | |
const logoPipeline = sharp(logoBuffer); | |
logoPipeline.resize({ width: 100, height: 100 }); | |
const imgPipeline = sharp(imgBuffer); | |
imgPipeline.resize({ width: 800 }); | |
imgPipeline.composite([{ input: await logoPipeline.toBuffer(), gravity: 'center' }]); | |
imgPipeline.jpeg({ quality: 70 }); | |
const outBuffer = await imgPipeline.toBuffer(); | |
return res.end(outBuffer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment