Please bookmark this page to avoid losing your image tool!

Image File Name Formatter

(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.
/**
 * Formats a file name by generating a new random name and extension.
 * This function's behavior is derived from the tool description "a0965a29vv.ibiiqijy_lf@",
 * which is interpreted as a template for a randomly generated file name.
 * The template suggests a 10-character alphanumeric name and a 12-character "extension"
 * from a specific character set. This function allows customization of these parameters.
 *
 * @param {Image} originalImg The original image object (required by API, but not used directly in this implementation).
 * @param {number} [nameLength=10] The desired length for the random name part of the file.
 * @param {number} [extLength=12] The desired length for the random extension part of the file.
 * @param {string} [nameCharset='abcdefghijklmnopqrstuvwxyz0123456789'] The set of characters to choose from for the name part.
 * @param {string} [extCharset='abcdefghijklmnopqrstuvwxyz_@'] The set of characters to choose from for the extension part, based on the example.
 * @returns {HTMLElement} A single HTML element styled to display the newly formatted file name.
 */
function processImage(
    originalImg,
    nameLength = 10,
    extLength = 12,
    nameCharset = 'abcdefghijklmnopqrstuvwxyz0123456789',
    extCharset = 'abcdefghijklmnopqrstuvwxyz_@'
) {
    /**
     * Generates a cryptographically secure random string if possible, otherwise falls back to Math.random.
     * @param {number} length The length of the string to generate.
     * @param {string} chars The character set to use.
     * @returns {string} The generated random string.
     */
    const generateRandomString = (length, chars) => {
        // Basic validation
        const len = parseInt(length, 10);
        if (isNaN(len) || len <= 0 || typeof chars !== 'string' || chars.length === 0) {
            return '';
        }

        let result = '';
        const charsLength = chars.length;

        // Use crypto.getRandomValues for better randomness if available
        if (window.crypto && window.crypto.getRandomValues) {
            const randomValues = new Uint32Array(len);
            window.crypto.getRandomValues(randomValues);
            for (let i = 0; i < len; i++) {
                result += chars[randomValues[i] % charsLength];
            }
        } else {
            // Fallback for older browsers or non-secure contexts
            for (let i = 0; i < len; i++) {
                result += chars.charAt(Math.floor(Math.random() * charsLength));
            }
        }
        return result;
    };

    // Generate the random name and extension parts
    const randomName = generateRandomString(nameLength, nameCharset);
    const randomExt = generateRandomString(extLength, extCharset);

    // Combine them to form the final formatted name
    const formattedName = `${randomName}.${randomExt}`;

    // Create a container element to display the result nicely
    const container = document.createElement('div');
    container.style.fontFamily = 'monospace, "Courier New", Courier';
    container.style.padding = '1rem';
    container.style.border = '1px solid #e0e0e0';
    container.style.borderRadius = '8px';
    container.style.backgroundColor = '#f7f7f7';
    container.style.textAlign = 'center';
    container.style.maxWidth = '100%';
    container.style.boxSizing = 'border-box';


    const title = document.createElement('p');
    title.textContent = 'Formatted File Name:';
    title.style.margin = '0 0 0.5rem 0';
    title.style.fontWeight = 'bold';
    title.style.color = '#333';
    title.style.fontSize = '1rem';

    const output = document.createElement('p');
    output.textContent = formattedName;
    output.style.margin = '0';
    output.style.color = '#0056b3';
    output.style.wordBreak = 'break-all';
    output.style.padding = '0.5rem';
    output.style.backgroundColor = '#ffffff';
    output.style.border = '1px dashed #ccc';
    output.style.borderRadius = '4px';
    output.style.fontSize = '1.1rem';

    container.appendChild(title);
    container.appendChild(output);

    return container;
}

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 File Name Formatter is a tool designed to generate uniquely formatted file names for images. It creates a random alphanumeric name combined with a randomized extension, customizable in length and character set. This utility is particularly useful for users looking to anonymize file names, save multiple versions of images without overwriting, or simply manage their files with random identifiers for organizational purposes.

Leave a Reply

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