Please bookmark this page to avoid losing your image tool!

Image Code Link Translator

(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.
function processImage(originalImg, format = 'image/png', quality = 0.92) {
    // 1. Create a canvas element
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    // 2. Set canvas dimensions to match the image
    // Use naturalWidth/Height to get the original image dimensions
    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight;

    // 3. Draw the image onto the canvas
    ctx.drawImage(originalImg, 0, 0);

    // 4. Generate the Data URL (the "code link")
    let dataURL;
    try {
        // The quality argument is only applicable for 'image/jpeg' and 'image/webp'.
        // It will be ignored for 'image/png'. The value should be between 0 and 1.
        const validQuality = Math.max(0, Math.min(1, quality));
        dataURL = canvas.toDataURL(format, validQuality);
    } catch (e) {
        console.error("Error generating data URL, falling back to PNG:", e);
        // Fallback to PNG if the specified format is not supported
        dataURL = canvas.toDataURL('image/png');
    }

    // 5. Create the output element to display the result in a user-friendly way
    const container = document.createElement('div');
    container.style.fontFamily = 'Arial, sans-serif';
    container.style.padding = '15px';
    container.style.border = '1px solid #ccc';
    container.style.borderRadius = '8px';
    container.style.backgroundColor = '#f9f9f9';
    container.style.maxWidth = '100%';
    container.style.boxSizing = 'border-box';

    const title = document.createElement('h4');
    title.textContent = 'Image Data URL (Code Link):';
    title.style.marginTop = '0';
    title.style.marginBottom = '10px';
    title.style.color = '#333';
    container.appendChild(title);

    const textarea = document.createElement('textarea');
    textarea.value = dataURL;
    textarea.readOnly = true;
    textarea.style.width = '100%';
    textarea.style.boxSizing = 'border-box';
    textarea.style.height = '250px';
    textarea.style.padding = '10px';
    textarea.style.border = '1px solid #ddd';
    textarea.style.borderRadius = '4px';
    textarea.style.resize = 'vertical';
    textarea.style.wordBreak = 'break-all'; // Break the long string for readability
    textarea.style.fontFamily = 'monospace';
    textarea.style.fontSize = '12px';
    textarea.style.backgroundColor = '#fff';

    // Add a click-to-select-all functionality for user convenience
    textarea.addEventListener('focus', (event) => {
        event.target.select();
    });

    container.appendChild(textarea);
    
    const copyButton = document.createElement('button');
    copyButton.textContent = 'Copy to Clipboard';
    copyButton.style.display = 'block';
    copyButton.style.marginTop = '10px';
    copyButton.style.padding = '10px 15px';
    copyButton.style.border = 'none';
    copyButton.style.backgroundColor = '#007bff';
    copyButton.style.color = 'white';
    copyButton.style.borderRadius = '4px';
    copyButton.style.cursor = 'pointer';
    copyButton.style.transition = 'background-color 0.2s';

    copyButton.onmouseover = () => { copyButton.style.backgroundColor = '#0056b3'; };
    copyButton.onmouseout = () => { copyButton.style.backgroundColor = '#007bff'; };

    copyButton.addEventListener('click', () => {
        // Use the modern Clipboard API if available
        if (navigator.clipboard && window.isSecureContext) {
            navigator.clipboard.writeText(textarea.value).then(() => {
                const originalText = copyButton.textContent;
                copyButton.textContent = 'Copied!';
                copyButton.style.backgroundColor = '#28a745';
                setTimeout(() => {
                    copyButton.textContent = originalText;
                    copyButton.style.backgroundColor = '#007bff';
                }, 2000);
            }).catch(err => {
                console.error('Failed to copy text using Clipboard API: ', err);
                alert('Failed to copy. Please copy the text manually.');
            });
        } else {
            // Fallback for older browsers
            textarea.select();
            try {
                document.execCommand('copy');
                const originalText = copyButton.textContent;
                copyButton.textContent = 'Copied!';
                copyButton.style.backgroundColor = '#28a745';
                setTimeout(() => {
                    copyButton.textContent = originalText;
                    copyButton.style.backgroundColor = '#007bff';
                }, 2000);
            } catch (err) {
                console.error('Failed to copy text using execCommand: ', err);
                alert('Failed to copy. Please copy the text manually.');
            }
        }
    });
    
    container.appendChild(copyButton);

    // 6. Return the container element
    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 Code Link Translator is a web tool designed to convert images into a data URL format, allowing users to easily generate and share image links. This tool is particularly useful for web developers, graphic designers, and content creators who need to embed images directly into HTML code or share image links without using traditional hosting. By simply uploading an image, users can receive a coded link that represents the image, making it easy to include in various applications such as websites, emails, or social media posts.

Leave a Reply

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