Please bookmark this page to avoid losing your image tool!

Image Circular Guides Adder

(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,
    numCircles = 3,
    lineColor = "rgba(255, 0, 0, 0.5)",
    lineWidth = 1,
    centerX = "50%",
    centerY = "50%",
    maxRadius = "45%"
) {
    // Convert parameters to their intended types, providing safety for numeric values.
    // parseInt/parseFloat will handle if they are already numbers or string representations.
    const _numCircles = parseInt(String(numCircles), 10);
    const _lineWidth = parseFloat(String(lineWidth));

    const canvas = document.createElement('canvas');
    // Use naturalWidth/Height for actual image dimensions, fallback to width/height
    const canvasWidth = originalImg.naturalWidth || originalImg.width;
    const canvasHeight = originalImg.naturalHeight || originalImg.height;

    canvas.width = canvasWidth;
    canvas.height = canvasHeight;

    const ctx = canvas.getContext('2d');

    // Draw the original image onto the canvas.
    // A try-catch block can be useful if originalImg might be in an error state,
    // though drawImage is generally robust with valid Image objects.
    try {
        ctx.drawImage(originalImg, 0, 0, canvasWidth, canvasHeight);
    } catch (e) {
        console.error("Error drawing original image: ", e);
        // Return the canvas, potentially empty or partially drawn, if image fails.
        // This ensures a canvas is always returned as per requirements.
        return canvas;
    }
    
    // If canvas dimensions are zero (e.g., image not loaded or is a 0x0 image),
    // no guides can be meaningfully drawn. The image (if any) is already on the canvas.
    if (canvasWidth === 0 || canvasHeight === 0) {
        return canvas;
    }

    // Helper function to parse dimension values.
    // These values can be numbers (interpreted as pixels) or strings ending with '%' (percentage).
    const parseUnitValue = (value, totalSize) => {
        const valStr = String(value).trim(); // Ensure value is a string and trim whitespace
        if (valStr.endsWith('%')) {
            // Calculate value from percentage
            return (parseFloat(valStr.slice(0, -1)) / 100) * totalSize;
        }
        // Assume pixels if no '%' suffix. parseFloat handles strings like "100px" by parsing "100".
        return parseFloat(valStr);
    };

    // Calculate final pixel values for center coordinates and maximum radius
    const _centerX = parseUnitValue(centerX, canvasWidth);
    const _centerY = parseUnitValue(centerY, canvasHeight);
    
    // maxRadius is interpreted as a percentage of the smaller image dimension, or a fixed pixel value.
    const smallerDimension = Math.min(canvasWidth, canvasHeight);
    const _maxRadius = parseUnitValue(maxRadius, smallerDimension);

    // Proceed to draw circular guides only if all numeric parameters are valid
    // and define drawable shapes (e.g., positive number of circles, positive line width).
    if (
        !isNaN(_numCircles) && _numCircles > 0 &&
        !isNaN(_lineWidth) && _lineWidth > 0 &&
        !isNaN(_centerX) && // Check if centerX resolved to a valid number
        !isNaN(_centerY) && // Check if centerY resolved to a valid number
        !isNaN(_maxRadius) && _maxRadius > 0 // Check if maxRadius is a positive number
    ) {
        ctx.strokeStyle = String(lineColor); // Ensure lineColor is treated as a string (for valid CSS color string)
        ctx.lineWidth = _lineWidth;

        const radiusStep = _maxRadius / _numCircles;

        for (let i = 1; i <= _numCircles; i++) {
            const currentRadius = radiusStep * i;
            
            // currentRadius will be positive if _maxRadius and _numCircles are positive.
            ctx.beginPath();
            ctx.arc(_centerX, _centerY, currentRadius, 0, 2 * Math.PI); // Draw a full circle
            ctx.stroke();
        }
    }

    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 Circular Guides Adder is a tool designed to overlay circular guides onto an image. Users can specify the number of circles, their color, width, and the center position, as well as the maximum radius of the circles as a percentage of the image dimensions. This tool can be particularly useful for graphic designers, artists, and educators who need to create visual aids, presentations, or annotations on images. It allows users to add precise circular guides for alignment or artistic purposes, enhancing the functionality of their images.

Leave a Reply

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

Other Image Tools:

Image Center Cropper

Image Petzval Lens Swirly Bokeh Effect Creator

Image Mimiya 645 Medium Format Filter Effect Tool

Photo Fujifilm Klasse W Filter Effect Application

Image Deardorff Large Format Filter Effect Application

Image Lomo LC-A Filter Effect Tool

Image Large Format Filter Effect Application

Image Zone Plate Lens Effect Creator

Photo Kodak Retina Filter Effect Tool

Image Polaroid 600 Filter Effect Tool

Photo Black and White Yellow Filter Effect Tool

Image Contax G2 Film Camera Render Effect Applicator

Image 110 Film Format Filter Effect Tool

Photo Jupiter-9 Portrait Lens Filter Effect

Image Fujifilm GW690 Texas Leica Filter Effect Application

Image Zeiss T* Coating Filter Effect Tool

Image Hoya R72 Infrared Filter Effect Tool

Image Filter Effect for Zeiss Ikon Contaflex

Photo Olympus Mju-II/Stylus Epic Filter Effect Tool

Image NiSi Nano IR ND Filter Effect Tool

Image Polaroid SX-70 Filter Effect Tool

Image Linhof Technika Filter Effect Tool

Image Lee Big Stopper 10-Stop ND Filter Effect Tool

Image Minolta X-700 Film Camera Render Effect Creator

Image ORWO UN54 Motion Picture Film Effect Applicator

Image Shen-Hao Large Format Filter Effect Tool

Image Impossible Project Polaroid Filter Effect Tool

Photo Foma Retropan 320 Film Filter Effect Tool

Image Fuji QuickSnap Disposable Filter Effect Application

Image 220 Film Format Filter Effect

Image Black and White with Green #61 Filter Effect Tool

Image 35mm Panoramic Camera Filter Effect Tool

Image Hitech Firecrest ND Filter Effect Formatter

Photo Rodenstock Digital Vario ND Filter Effect Tool

Image Leica Yellow Filter Effect Application

Image Argus C3 Vintage Camera Filter Effect

See All →