Please bookmark this page to avoid losing your image tool!

Image Two Converter

(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, conversionType = "two-images", gapWidth = 0, threshold = 128) {
    const canvas = document.createElement("canvas");
    const ctx = canvas.getContext("2d");
    
    // Parse parameters to ensure valid numbers
    let gap = parseInt(gapWidth, 10);
    if (isNaN(gap)) gap = 0;
    
    let thresh = parseInt(threshold, 10);
    if (isNaN(thresh)) thresh = 128;

    // Based on the ambiguity of "Two" ("Два"), support three common interpretations:
    // 1. "2x-upscale" : Scales the image by a factor of two.
    // 2. "two-colors" : Converts the image to a two-color (black & white) binary format.
    // 3. "two-images" : Literally creates two copies of the image side-by-side.
    
    if (conversionType === "2x-upscale") {
        canvas.width = originalImg.width * 2;
        canvas.height = originalImg.height * 2;
        
        // Disable image smoothing for pixel-perfect 2x nearest-neighbor scaling if desired, 
        // otherwise let default bilinear smoothing happen.
        ctx.drawImage(originalImg, 0, 0, canvas.width, canvas.height);
        
    } else if (conversionType === "two-colors") {
        canvas.width = originalImg.width;
        canvas.height = originalImg.height;
        ctx.drawImage(originalImg, 0, 0);
        
        const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
        const data = imageData.data;
        
        for (let i = 0; i < data.length; i += 4) {
            // Skip fully transparent pixels
            if (data[i + 3] === 0) continue;

            // Calculate luminance using standard weights
            const r = data[i];
            const g = data[i + 1];
            const b = data[i + 2];
            const luminance = 0.299 * r + 0.587 * g + 0.114 * b;
            
            // Snap to two colors: black or white based on threshold
            const colorValue = luminance >= thresh ? 255 : 0;
            
            data[i] = colorValue;       // Red
            data[i + 1] = colorValue;   // Green
            data[i + 2] = colorValue;   // Blue
            // Alpha remains unmodified
        }
        
        ctx.putImageData(imageData, 0, 0);
        
    } else {
        // Default: "two-images" -> Side-by-side duplication
        canvas.width = (originalImg.width * 2) + gap;
        canvas.height = originalImg.height;
        
        // Draw first image on the left
        ctx.drawImage(originalImg, 0, 0);
        
        // Draw second image on the right (after the gap)
        ctx.drawImage(originalImg, originalImg.width + gap, 0);
    }

    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 Two Converter is a versatile utility that provides three distinct image processing modes: upscaling, color simplification, and duplication. Users can scale an image to twice its original size, convert an image into a high-contrast two-color (black and white) format using a customizable threshold, or create a side-by-side duplicate of an image with an optional gap between them. This tool is useful for graphic designers needing quick scaling, creators looking to make stylized binary art, or anyone needing to generate simple mirrored or repetitive image compositions.

Leave a Reply

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