Please bookmark this page to avoid losing your image tool!

Bulge X Image Effect Generator

(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.
/**
 * Applies a Bulge X effect to an image. The effect distorts the image by magnifying (bulge)
 * or shrinking (pinch) horizontally along the X-axis while leaving the Y-axis intact.
 * 
 * @param {HTMLImageElement} originalImg - The input image object.
 * @param {number|string} amount - The strength of the bulge effect [-1.0 to 1.0]. Positive is bulge, negative is pinch. Default is 0.5.
 * @param {number|string} radius - The radius of the effect relative to the image width [0.0 to 1.0]. Default is 0.5.
 * @param {number|string} centerX - The center position of the effect on the X-axis [0.0 to 1.0]. Default is 0.5.
 * @returns {HTMLCanvasElement} - A canvas element containing the processed image.
 */
function processImage(originalImg, amount = 0.5, radius = 0.5, centerX = 0.5) {
    // Parse parameters
    const amt = Number(amount);
    const rad = Number(radius);
    const cxRatio = Number(centerX);

    // Setup canvas
    const canvas = document.createElement('canvas');
    const width = originalImg.width;
    const height = originalImg.height;
    canvas.width = width;
    canvas.height = height;

    const ctx = canvas.getContext('2d');
    ctx.drawImage(originalImg, 0, 0, width, height);

    // If there is no distortion applied, return the original drawn canvas early
    if (amt === 0 || rad <= 0) {
        return canvas;
    }

    const srcImageData = ctx.getImageData(0, 0, width, height);
    const srcData = srcImageData.data;
    const dstImageData = ctx.createImageData(width, height);
    const dstData = dstImageData.data;

    // Convert normalized parameters to pixel values
    const cx = cxRatio * width;
    const r = rad * width;

    // Precompute X-axis distortion mapping
    // Since the Bulge X effect operates entirely in 1D horizontally, we can precalculate 
    // the source pixels and interpolation weights for a single row to maximize performance.
    const safeX1 = new Int32Array(width);
    const safeX2 = new Int32Array(width);
    const wx = new Float32Array(width);
    const iwx = new Float32Array(width);

    for (let x = 0; x < width; x++) {
        let dx = x - cx;
        let distance = Math.abs(dx);
        let srcX = x;

        // Apply distortion if the pixel falls within the bulging radius
        if (distance < r && r > 0) {
            let ratio = distance / r;
            // Using a cubic polynomial distortion mapping mapping
            srcX = cx + dx * (1 - amt * (1 - ratio * ratio));
        }

        // Setup linear interpolation values
        let x1 = Math.floor(srcX);
        let x2 = x1 + 1;
        let weight = srcX - x1;

        // Clamp the sampled source pixels to essentially handle edges gracefully
        safeX1[x] = x1 < 0 ? 0 : (x1 >= width ? width - 1 : x1);
        safeX2[x] = x2 < 0 ? 0 : (x2 >= width ? width - 1 : x2);
        wx[x] = weight;
        iwx[x] = 1.0 - weight;
    }

    // Apply mapping looping over Height -> Width
    for (let y = 0; y < height; y++) {
        let yOffset = y * width;
        for (let x = 0; x < width; x++) {
            // Left shift by 2 is functionally equivalent to multiplying by 4 (RGBA bytes)
            let dstIdx = (yOffset + x) << 2; 
            let idx1 = (yOffset + safeX1[x]) << 2;
            let idx2 = (yOffset + safeX2[x]) << 2;
            
            let weightX = wx[x];
            let invWeightX = iwx[x];

            // Bilinear interpolation computationally simplified to horizontal space (Linear)
            dstData[dstIdx]     = srcData[idx1]     * invWeightX + srcData[idx2]     * weightX;
            dstData[dstIdx + 1] = srcData[idx1 + 1] * invWeightX + srcData[idx2 + 1] * weightX;
            dstData[dstIdx + 2] = srcData[idx1 + 2] * invWeightX + srcData[idx2 + 2] * weightX;
            dstData[dstIdx + 3] = srcData[idx1 + 3] * invWeightX + srcData[idx2 + 3] * weightX;
        }
    }

    // Draw the calculated altered pixel data back to canvas
    ctx.putImageData(dstImageData, 0, 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 Bulge X Image Effect Generator allows you to apply horizontal distortion effects to your images. You can use it to create a ‘bulge’ effect to magnify specific areas horizontally or a ‘pinch’ effect to shrink them. Users can customize the strength of the distortion, the radius of the affected area, and the horizontal center position where the effect is applied. This tool is ideal for creative photo editing, creating stylized or surreal imagery, or producing fun visual distortions for social media and digital art.

Leave a Reply

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

Other Image Tools:

UN Owen Was X Image Effect Generator

Sunflowered Image Effect Generator

Doorbell Image Generator

Dewdrop Image Effect Generator

Image Crystal Drop Effect Applicator

Chess Image Generator

Cave Image Generator

Bongo Image Tool

Image Bongo Generator

Birdsong Image Generator

Image Bell Generator

Colorado Driver License Fictional Person Generator

Fake Driver License Image Generator

35mm 2960×1800 Ratio Resolution Image Resizer

The Lion King 1994 IMAX 70mm Movie Trailer Image

Big Hero 6 Character Replacement AI Tool for Video and Image

Big Hero 6 Character Replace AI Image and Video Tool

Big Hero 6 To Big Hero 6 The Series AU Replacement Tool

Big Hero 6 To Big Hero 6 The Series AU Image and Video Replacer

Slow Motion Video and Audio Playback Tool

Image Speed Reduction Tool

YouTube Stats For Nerds Audio Volume Normalization Analysis Tool

YouTube Stats For Nerds Audio Volume Normalization Information Tool

YouTube Stats For Nerds Volume Normalization Analyzer

YouTube Stats For Nerds Audio Volume Normalization Analyzer

YouTube Stats For Nerds Volume Normalization Analysis Tool

YouTube Stats For Nerds Audio Volume Normalization Information Display

YouTube Stats For Nerds Volume Normalization Information Tool

YouTube Stats For Nerds Audio Volume and Codec Information Extractor

YouTube Audio Stats Volume Normalization Tool for Mp2 Mp3 Opus and Ac3

Audio Volume Normalizer for Mp2 Mp3 Opus and Ac3 Formats

YouTube Audio Stats Volume Normalizer For Mp2 Mp3 Opus and Ac3 Formats

United States of America Federal Social Security Card Template Maker

Ukrainian Dub Master Video Voice Actor Information Tool

Ukrainian Dubbed Video Voice Actor Information Tool

YouTube Stats For Nerds Volume Normalizer for Opus and Ac3 Audio

See All →