Please bookmark this page to avoid losing your image tool!

Image Title Creator

(Free & Supports Bulk Upload)

Drag & drop your images here or

The result will appear here...
You can edit the below JavaScript code to customize the image tool.
/**
 * Creates an image with a title bar at the top or bottom.
 *
 * @param {Image} originalImg The original image object to add a title to.
 * @param {string} titleText The text to display in the title bar.
 * @param {number} fontSize The size of the font in pixels.
 * @param {string} fontFamily The CSS font-family string for the title text.
 * @param {string} fontColor A CSS color string for the title text.
 * @param {string} backgroundColor A CSS color string for the title bar's background.
 * @param {string} position The position of the title bar, either 'top' or 'bottom'.
 * @param {number} padding The vertical padding (in pixels) inside the title bar.
 * @returns {HTMLCanvasElement} A new canvas element containing the image with the added title.
 */
function processImage(
    originalImg,
    titleText = 'My Image Title',
    fontSize = 48,
    fontFamily = 'Impact, sans-serif',
    fontColor = 'white',
    backgroundColor = 'rgba(0, 0, 0, 0.6)',
    position = 'bottom',
    padding = 20
) {
    // Ensure numeric parameters are treated as numbers
    const numFontSize = Number(fontSize);
    const numPadding = Number(padding);

    // Calculate the required height for the title bar
    const titleBarHeight = numFontSize + (numPadding * 2);

    // Create a new canvas
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // Set the canvas dimensions to fit the image and the new title bar
    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight + titleBarHeight;

    let imageY, titleBarY, textY;

    // Determine the Y coordinates for drawing based on the desired position
    if (position === 'top') {
        imageY = titleBarHeight;
        titleBarY = 0;
        textY = titleBarHeight / 2;
    } else { // Default to 'bottom'
        imageY = 0;
        titleBarY = originalImg.naturalHeight;
        textY = originalImg.naturalHeight + titleBarHeight / 2;
    }

    // Draw the original image onto the canvas
    ctx.drawImage(originalImg, 0, imageY, originalImg.naturalWidth, originalImg.naturalHeight);

    // Draw the background for the title bar
    ctx.fillStyle = backgroundColor;
    ctx.fillRect(0, titleBarY, canvas.width, titleBarHeight);

    // Set the text style and draw the title text
    ctx.font = `${numFontSize}px ${fontFamily}`;
    ctx.fillStyle = fontColor;
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // Add a simple stroke for better readability on complex backgrounds
    ctx.strokeStyle = 'black';
    ctx.lineWidth = numFontSize / 20; // Stroke width relative to font size
    ctx.strokeText(titleText, canvas.width / 2, textY);
    ctx.fillText(titleText, canvas.width / 2, textY);

    return canvas;
}

Free Image Tool Creator

Can't find the image tool you're looking for?
Create one based on your own needs now!

Description

The Image Title Creator tool allows users to add a customizable title bar to images. Users can specify the title text, font size, font family, font color, and background color of the title bar, as well as its position (either at the top or bottom of the image). This tool can be particularly useful for creating visually appealing images for social media posts, presentations, or online galleries, where a clear title or label enhances the viewer’s experience.

Leave a Reply

Your email address will not be published. Required fields are marked *