You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, title = "Доставка Продуктов", price = "500 ₽", deliveryTime = "15-30 мин", rating = "4.8 ★", promoText = "Скидка 20%") {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// Set fixed card dimensions typically used in food delivery UI
const targetWidth = 800;
const targetHeight = 600;
canvas.width = targetWidth;
canvas.height = targetHeight;
// Helper for rounded rectangles (ensures cross-browser compatibility)
function fillRoundRect(x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
ctx.fill();
}
// 1. Draw Image with Object-Cover sizing to fit the 800x600 card perfectly
const scale = Math.max(targetWidth / originalImg.width, targetHeight / originalImg.height);
const drawW = originalImg.width * scale;
const drawH = originalImg.height * scale;
const drawX = (targetWidth - drawW) / 2;
const drawY = (targetHeight - drawH) / 2;
ctx.drawImage(originalImg, drawX, drawY, drawW, drawH);
// 2. Draw Bottom Dark Gradient for readability
const gradient = ctx.createLinearGradient(0, targetHeight * 0.4, 0, targetHeight);
gradient.addColorStop(0, 'rgba(0,0,0,0)');
gradient.addColorStop(0.6, 'rgba(0,0,0,0.7)');
gradient.addColorStop(1, 'rgba(0,0,0,0.9)');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, targetWidth, targetHeight);
// 3. Typography setup
const fontFamily = "'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif";
ctx.textBaseline = 'middle';
// 4. Promo Badge (Top Left)
if (promoText) {
ctx.font = `bold 24px ${fontFamily}`;
const promoWidth = ctx.measureText(promoText).width;
ctx.fillStyle = '#00c354'; // Fresh Green
fillRoundRect(30, 30, promoWidth + 30, 46, 12);
ctx.fillStyle = '#ffffff';
ctx.fillText(promoText, 45, 54);
}
// 5. Title / Service Name
ctx.font = `bold 48px ${fontFamily}`;
ctx.fillStyle = '#ffffff';
// Add text shadow for extra pop
ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
ctx.shadowBlur = 10;
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
const titleX = 40;
const titleY = targetHeight - 140;
ctx.fillText(title, titleX, titleY);
// Reset shadow for badges
ctx.shadowColor = 'transparent';
// 6. Badges Row (Price, Delivery Time, Rating)
const badgeY = targetHeight - 80;
const badgeHeight = 50;
const badgeRadius = 16;
let currentX = titleX;
// Price Badge
if (price) {
ctx.font = `bold 28px ${fontFamily}`;
const priceWidth = ctx.measureText(price).width;
ctx.fillStyle = '#ff4500'; // Appetizing Orange-Red
fillRoundRect(currentX, badgeY, priceWidth + 40, badgeHeight, badgeRadius);
ctx.fillStyle = '#ffffff';
ctx.fillText(price, currentX + 20, badgeY + (badgeHeight / 2));
currentX += priceWidth + 60;
}
// Delivery Time Badge
if (deliveryTime) {
ctx.font = `bold 24px ${fontFamily}`;
const timeWidth = ctx.measureText(deliveryTime).width;
ctx.fillStyle = 'rgba(255, 255, 255, 0.25)'; // Translucent White
fillRoundRect(currentX, badgeY, timeWidth + 40, badgeHeight, badgeRadius);
ctx.fillStyle = '#ffffff';
ctx.fillText(deliveryTime, currentX + 20, badgeY + (badgeHeight / 2));
currentX += timeWidth + 60;
}
// Rating Badge
if (rating) {
ctx.font = `bold 24px ${fontFamily}`;
const ratingWidth = ctx.measureText(rating).width;
ctx.fillStyle = '#ffc107'; // Golden Amber
fillRoundRect(currentX, badgeY, ratingWidth + 40, badgeHeight, badgeRadius);
ctx.fillStyle = '#212529'; // Dark text
ctx.fillText(rating, currentX + 20, badgeY + (badgeHeight / 2));
}
return canvas;
}
Apply Changes