UNPKG

almtools

Version:

Tools Downloader For WhatsApp Bot

130 lines (92 loc) 3.59 kB
const { createCanvas, loadImage } = require('canvas'); const fs = require('fs'); const Jimp = require("jimp"); async function thumbnail1({ profilePicture, title1, title2, profilePicture2 }) { try { const canvas = createCanvas(1920, 1080); const ctx = canvas.getContext('2d'); const template = await loadImage('https://i.ibb.co/QFxK3Nrd/996c4aaed031.png'); ctx.drawImage(template, 0, 0, canvas.width, canvas.height); const pfp = await loadImage(profilePicture); const pfpSize = 571; const pfpX = 870.27 - pfpSize / 2; const pfpY = 532.90 - pfpSize / 2; ctx.save(); ctx.beginPath(); ctx.roundRect(pfpX, pfpY, pfpSize, pfpSize, 30); ctx.clip(); ctx.drawImage(pfp, pfpX, pfpY, pfpSize, pfpSize); ctx.restore(); ctx.strokeStyle = '#ffffff'; ctx.lineWidth = 6; ctx.beginPath(); ctx.roundRect(pfpX, pfpY, pfpSize, pfpSize, 30); ctx.stroke() let jembud = await loadImage("https://i.ibb.co/9msHyJ2D/ae032c0e841b.png"); ctx.save() ctx.drawImage(jembud, (960 - 1920 / 2), (541/ -1080 / 2), 1920, 1080); const pfp2 = await loadImage(profilePicture2); const pfp2Size = 150; const pfp2X = 608.34 - pfp2Size / 2; const pfp2Y = 274.96 - pfp2Size / 2; ctx.save(); ctx.beginPath(); ctx.roundRect(pfp2X, pfp2Y, pfp2Size, pfp2Size, 30); ctx.clip(); ctx.drawImage(pfp2, pfp2X, pfp2Y, pfp2Size, pfp2Size); ctx.restore(); ctx.strokeStyle = '#ffffff'; ctx.lineWidth = 6; ctx.beginPath(); ctx.roundRect(pfp2X, pfp2Y, pfp2Size, pfp2Size, 30); ctx.stroke(); ctx.save(); ctx.rotate(42 * Math.PI / 180); const x = 238.83 const y = 814.96 const angle = 42 * Math.PI / 180; const rotatedX = x * Math.cos(angle) + y * Math.sin(angle); const rotatedY = y * Math.cos(angle) - x * Math.sin(angle); ctx.translate(rotatedX, rotatedY); ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillStyle = '#000000'; ctx.font = 'bold 64px Arial'; ctx.fillText(title1 || "", 0, 0); ctx.restore(); ctx.save(); ctx.rotate(42 * Math.PI / 180); const yx = 1729.3939 const yy = 186.43661 const rangle = 42 * Math.PI / 180; const rotateX = yx * Math.cos(rangle) + yy * Math.sin(rangle); const rotateY = yy * Math.cos(rangle) - yx * Math.sin(rangle); ctx.translate(rotateX, rotateY); ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillStyle = '#000000'; ctx.font = 'bold 48px Arial'; ctx.fillText(title2 || "", 0, 0); ctx.restore(); let kontol = await loadImage("https://i.ibb.co/SX7c904d/690ac5535553.png"); ctx.save() ctx.drawImage(kontol, (1291.10 - 1080 / 2), (541 -1080 / 2), 1080, 1080); ctx.restore() const buffer = canvas.toBuffer('image/png'); return resize(buffer) || buffer; } catch (error) { console.error('Error:', error.message); throw error; } } module.exports = { thumbnail1 } async function resize(buffer) { try { const image = await Jimp.read(buffer); image.resize(1280, 720); const output = await image.getBufferAsync(Jimp.MIME_PNG); return output } catch (error) { throw error; } }