Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I double the size of an image on a web page?

Tags:

I have an image, say 320 x 240 pixels in size, which I want to display doubled in size (i.e. 640 x 480 pixels) on a web page. In the past, I have done this by setting width=640 on the img tag.

However, I have just spotted the following in the HTML specification:

The dimension attributes are not intended to be used to stretch the image.

In that case, how do I double the size of an image on a web page without going against what the spec intends?

like image 461
user200783 Avatar asked Apr 02 '18 16:04

user200783


People also ask

How do I make a picture bigger on a website?

If you want to make an image larger:Change the scale % to something over a hundred. For example if you want a picture to be double the size then set it to 200%. For example if you have an image that is 800 x 800 pixels, and you scale it to 200% then it will come out as 1600 x 1600.

How do I increase the size of an image in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.

How is it possible to change the display size of an image in a web page without altering the size of original image explain with the help of an example?

There is no command for changing an image size. Image dimensions are 'properties' which can be expressed in either the HTML <img> element, as width="150" height="100" attributes in the tag; or, the CSS as style rules applying to specific images.


2 Answers

You can use CSS instead. The two methods that jump to mind are using the width or scale transformation.

E.g. img { width: 640px; }. This will keep the proper aspect ratio without specifying the height.

img {    width: 640px;  }
<img src="http://www.placehold.it/320x240">

E.g. img { transform: scale(2) }

img {    transform-origin: top left;    transform: scale(2);  }
<img src="http://www.placehold.it/320x240">
like image 162
j08691 Avatar answered Sep 29 '22 14:09

j08691


You can set the dimension of the parent image container

.imageContainer {    width: 640px;    height: 480px;  }    img {    width: 100%;    height: 100%  }
<div class="imageContainer">      <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQqdnZQDnZOOyBGXXB23WS87IAxZ85drC-ylgrqWCqYk2aEh3Vo">  </div>
like image 42
brk Avatar answered Sep 29 '22 14:09

brk