You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, stampText = "ВОЕННАЯ ТАЙНА", pixelSize = 10, isGrayscale = 1, stampColor = "#cc0000") {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = originalImg.width;
canvas.height = originalImg.height;
// Parse options
const pixelate = Math.max(1, parseInt(pixelSize) || 1);
const useGrayscale = parseInt(isGrayscale) === 1;
// Draw the image onto the canvas with pixelation and/or grayscale effects
if (pixelate > 1) {
const w = Math.max(1, Math.floor(canvas.width / pixelate));
const h = Math.max(1, Math.floor(canvas.height / pixelate));
const tempCanvas = document.createElement('canvas');
tempCanvas.width = w;
tempCanvas.height = h;
const tempCtx = tempCanvas.getContext('2d');
if (useGrayscale) {
tempCtx.filter = 'grayscale(100%) contrast(1.2)';
}
tempCtx.drawImage(originalImg, 0, 0, w, h);
ctx.imageSmoothingEnabled = false;
ctx.drawImage(tempCanvas, 0, 0, w, h, 0, 0, canvas.width, canvas.height);
} else {
if (useGrayscale) {
ctx.filter = 'grayscale(100%) contrast(1.2)';
}
ctx.drawImage(originalImg, 0, 0, canvas.width, canvas.height);
ctx.filter = 'none';
}
// Apply the "Military Secret" stamp
if (stampText && stampText.trim() !== '') {
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
// Rotate slightly for a realistic stamp look (-15 degrees)
const angle = -15 * Math.PI / 180;
ctx.rotate(angle);
// Responsive font sizing
const diag = Math.sqrt(canvas.width * canvas.width + canvas.height * canvas.height);
let fontSize = diag * 0.1;
ctx.font = `bold ${fontSize}px "Courier New", Courier, monospace`;
let metrics = ctx.measureText(stampText);
// Adjust font size so that text takes up about 80% of width
const targetWidth = canvas.width * 0.8;
fontSize = fontSize * (targetWidth / Math.max(1, metrics.width));
// Clamp font size to reasonable limits
fontSize = Math.max(15, Math.min(fontSize, canvas.height * 0.4));
ctx.font = `bold ${fontSize}px "Courier New", Courier, monospace`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// Re-measure with final font size bounds
metrics = ctx.measureText(stampText);
const textWidth = metrics.width;
const paddingX = fontSize * 0.5;
const paddingY = fontSize * 0.4;
const rectWidth = textWidth + paddingX * 2;
const rectHeight = fontSize + paddingY * 2;
// Stamp visuals
ctx.globalAlpha = 0.8;
ctx.strokeStyle = stampColor;
ctx.fillStyle = stampColor;
// Draw thick outer bordered rectangle
ctx.lineWidth = Math.max(3, fontSize * 0.08);
ctx.strokeRect(-rectWidth / 2, -rectHeight / 2, rectWidth, rectHeight);
// Draw thinner inner bordered rectangle
const innerPadding = ctx.lineWidth * 1.5;
ctx.lineWidth = Math.max(1, fontSize * 0.03);
ctx.strokeRect(
-rectWidth / 2 + innerPadding,
-rectHeight / 2 + innerPadding,
rectWidth - innerPadding * 2,
rectHeight - innerPadding * 2
);
// Draw the main stamp text
ctx.fillText(stampText, 0, 0);
ctx.restore();
}
return canvas;
}
Apply Changes