I have 3 different sizes for the same image.
Can I achieve something like the following:
<img src='/path/to/image.jpg'></img>
<img src='/path/to/image.jpg?small'></img>
<img src='/path/to/image.jpg?large'></img>
I have tried the above but it instead shows image.jpg
The browser doesn't understand what you're trying to do. Why not append the size to the end of the image, like so:
<img src='/path/to/image.jpg></img>
<img src='/path/to/image.jpg_small></img>
<img src='/path/to/image.jpg_large></img>
I would suggest to keep the same image and add some css style to each one, instead of calling the same image 3 times from it path something like:
html code
<div>
<img src="/path/image.jpg" width="100" height="100">
</div>
<div id="scale-up" style="height: 230px">
<img src="/path/image.jpg">
</div>
<div id="scale-down" style="height: 57px">
<img src="/path/image.jpg">
css code
img {
vertical-align: middle;
height: 100%;
}
#scale-up {
height: 230px;
}
#scale-down {
height: 57px;
}
If you want filenames to look like (on server):
fd11f91bb8361030bdc09d8b8ed4f88e?w=200&h=76&f=png
You need to url encode them when requesting to server. For example using http://meyerweb.com/eric/tools/dencoder/
So url encoded file will look like:
fd11f91bb8361030bdc09d8b8ed4f88e%3Fw%3D200%26h%3D76%26f%3Dpng
So in your case it should be:
<img src='/path/to/image.jpg'></img>
<img src='/path/to/image.jpg%3Fsmall'></img>
<img src='/path/to/image.jpg%3Flarge'></img>
Like #Leo mentioned, using html-tags (or css) is much easier here than a url-based approach. (which would require server logic)
The html-tag resizing would look like:
<img src="/path/to/image.jpg" width="100" height="100">
You mention that you dislike how that might increase the bandwidth usage. This shouldn't be a problem as long as your website uses caching on the images. (it will only download the image once then, and just resize the same image locally for the different tags)
I would suggest
<img src="/path/to/image.jpg"></img>
<img src="/path/to/image_small.jpg"></img>
<img src="/path/to/image_large.jpg"></img>
to keep the file extension.
Related
My HTML code is not displaying the image. I have tried a lot of times.
<img style="width: 200px; height: 200px;" src="../static/aircondition.jpg" alt="Air Condition">
Output
Please check if your provided src directory is correct or not
Sorry, but I am very frustrated, I just want to insert a picture into my website.
<img src="example.jpg" alt="Example"/>
The file is in the same directory as the html.
What is wrong with that????????????
file tree:
Still it does not work :(
Edit:
./example.jpg does not work either ! :(
It just shows the alt... :(
Edit:
Seems like the problem comes from the CS50 IDE! I will try to upload the image to another website and then acces it :/
The tag is correct, but make sure that Example.jpg is in the same exact folder as the html file and check the file name and its extension too (it's case sensetive)
Bro, first check if the image you want is really on the same folder you're working on it and then:
<img src="./example.jpg" alt="Example" />
<img src="./example.jpg" alt="Example" />
you can also use picture tag in html like:
<picture>
<source media="(min-width:650px)" srcset="./example.jpg">
<source media="(min-width:465px)" srcset="./example01.jpg">
<img src="./example02.jpg" alt="Flowers" style="width:auto;">
</picture>
or you can have a simple div and add the picture using css like:
div {
background-image: url(./example.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 100vh; //change it to what you like
width: 100vw; //change it to what you like
}
The same thing has been use for another image that uses HTML, and it works fine, exept for this one : https://media.discordapp.net/attachments/604447563185127426/665665552324362260/BCS_Bottom_Bar.png
And when I put the URL the same way I did for my other image and the same elements used, Yet it doesn't work.
Can someone help me fix it ?
<div><img width="50" height="50" src="https://media.discordapp.net/attachments/604447563185127426/665665552324362260/BCS_Bottom_Bar.png?width=1260&height=117"></div>
I've tried many alternatives to the URL, but they all don't work, I even tried changing the name.
The img tag has two required attributes: src and alt.
So you have to change your href attribute to src.
<div><img width="50" height="50" src="https://media.discordapp.net/attachments/604447563185127426/665665552324362260/BCS_Bottom_Bar.png?width=1260&height=117"></div>
For more detail, take a look at; https://www.w3schools.com/tags/tag_img.asp
It loads this way, there are no issues in your html.
As the font color is white, you maybe need to give the div a black
background like this:
<div style="background: black">
<img width="50%" height="50%" src="https://media.discordapp.net/attachments/604447563185127426/665665552324362260/BCS_Bottom_Bar.png">
</div>
I changed your width and height attributes to 50 percent.
Demo:
https://jsfiddle.net/ohc50tx6/
I have met a strange problem. I am writing my blog post in Markdown. Occasionally, I need to include images and control and image size using HTML. I just include some HTML tags in Markdown. My code is like the following:
<p align="center">
<img src="https://blog-resource-1257868508.cos.ap-hongkong.myqcloud.com/20181225231628.png" width="200">
</p>
I found that setting the width attribute works as expected, but if I only set up the height attribute, the height attribute is ignored by the browser (tested both on chrome and safari).
I.E., the following HTML code does not work in setting up image height:
<p align="center">
<img src="https://blog-resource-1257868508.cos.ap-hongkong.myqcloud.com/20181225231430.png" height="200">
</p>
An example page is shown here. The first image is using height attribute only (height="200"), and the other images are using only width attribute (widht="200"). You can check the source code of the page to verify that.
BTW, I am using Hugo to generate the blog site for me. I do not if it is relevant.
Try wrapping your height in a style tag like this
<img src=“image.png” style=“height: 100px”>
You could also do something like this...
<p align="center">
<div class=imgContainer”>
<img src="https://blog-resource-1257868508.cos.ap-hongkong.myqcloud.com/20181225231628.png" width="200">
</div>
</p>
And
.imgContainer {
Height: 100px;
Width: 200px;
}
I have 6 images sized 50x50 that are supposed to fit in a 300px div (50 * 6 = 300).
In my code I write them as follows:
<img src="foo.png" />
<img src="foo.png" />
<img src="foo.png" />
<img src="foo.png" />
<img src="foo.png" />
<img src="foo.png" />
Note the line breaks in between the image tags. I write them that way for clarity.
The problem is that when I test the page in a browser - the images do not fit, because the browser adds a space for every line break so I end up with something like this:
[img][space][img][space][img][space][img][space][img][space][img][space]
instead of:
[img][img][img][img][img][img]
I can easily remove the line breaks from my html, but that makes my code a lot less readable.
I am working in Ruby on Rails 2.3 - if there's a helper function for stripping out whitespace, I don't mind using that.
I was wondering if anybody knows how I can avoid this.
Thanks!
If you're using the image_tag helper, you can do
the -%> will not include the spaces in output.
Put your images in a <div class="images"> and set your css rules to div.images img { float: left }.