How to set image width and height dynamically in javascript

    change image size in javascript
    change image resolution javascript
    change image size on click javascript
    how to change background image size in javascript
  • Change image size in javascript
  • Javascript get image size in kb

  • Javascript get image size in kb
  • Change image size on click javascript
  • Javascript image resize library
  • Javascript resize image keep aspect ratio
  • Resize image javascript w3schools
  • Javascript image resize library.

    Change size of an image with JavaScript/jQuery

    1.

    and property of the image.

    The following example demonstrates this by altering the CSS property by specifying the absolute value in pixels and leave the browser to calculate the corresponding while maintaining the aspect ratio.

    JS


    document.querySelector('button').onclick=function(){

        varimage=document.getElementById('container');

        image.style.width='156px';

        image.style.height='auto';

    }

    HTML


    <img id="container"src='https://avatars0.githubusercontent.com/u/70142' />

    <button>Resize</button>


    Edit in JSFiddle

     
    You can either provide an absolute value or value in percentage.

    The following example changes the size of an image relative to its original size.

    JS


    document.querySelector('button').onclick=function(){

        varimage=document.getElementById('container');

        image.style.width='50%';

        image.style.height='auto';

    }

      change image sizes
      javascript image size