You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
896 B
JavaScript
42 lines
896 B
JavaScript
import Jimp from 'jimp'
|
|
import { useRouter } from "next/router"
|
|
|
|
export default async function handler(req, res) {
|
|
const img = req.query.img
|
|
const baseURL = "https://orthoverse.io/api/img/"
|
|
|
|
try {
|
|
const image = await Jimp.read(baseURL + img)
|
|
const crest = image.clone().crop(3,5,60,96)
|
|
|
|
const level = parseInt(
|
|
img.substring(
|
|
img.indexOf("-") + 1,
|
|
img.lastIndexOf(".")
|
|
)
|
|
)
|
|
|
|
if (level % 8 > 0) {
|
|
image
|
|
.composite(crest, 10, 173, {
|
|
mode: Jimp.BLEND_SOURCE_OVER,
|
|
})
|
|
}
|
|
|
|
image
|
|
.crop(4,168,412,190)
|
|
.resize(316,143)
|
|
.getBuffer(Jimp.MIME_PNG, (err, buffer) => {
|
|
res.statusCode = 200
|
|
res.setHeader("Content-Type", "image/png");
|
|
res.write(buffer)
|
|
res.end()
|
|
})
|
|
} catch (err) {
|
|
console.log(err)
|
|
res.status(404)
|
|
res.json({ error: "Not found" })
|
|
res.end()
|
|
}
|
|
}
|