Function setImgSizeBySrc

  • Sets the width and height of all images on the page based on their src attribute. The src attribute should contain width and/or height values in the format "width=100" or "height=100". If jQuery is available, this function uses jQuery to select the images. Otherwise, it uses pure JavaScript.

    Usage:

    // Example images with `src` attributes containing `width` and/or `height` values
    const img1 = document.createElement("img");
    img1.setAttribute("src", "https://example.com/example.png?width=2233&height=111");
    document.body.appendChild(img1);

    const img2 = document.createElement("img");
    img2.setAttribute("src", "https://example.com/example.png?width=100%&height=auto");
    document.body.appendChild(img2);

    Returns boolean

    • Returns true if images were found and their dimensions were set, otherwise false.