I have to use Base64 embedded images in my html file like this:
<!DOCTYPE html>
<html>
<head>
<title>Display Image</title>
</head>
<body>
<img style='display:block; width:100px;height:100px;' id='base64image'
src='data:image/jpeg;base64, <!-- Base64 data -->' />
</body>
</html>
but my images size are more than 200k and the base64 data
part is really huge.
I need to put these image in other tag like script
and attach them there on run time.
I need something like this:
<!DOCTYPE html>
<html>
<head>
<title>Display Image</title>
</head>
<body>
<img style='display:block; width:100px;height:100px;' id='base64image'
src='data:image/jpeg;base64, readdata('mybase64imageid')' />
</body>
<some-tag id='mybase64imageid'>my base 64 image is written
here</some-tag>
</html>
2
Answers
To add "src" runtime into the image:
If you are looking for looping you can go with:
If you’re so concerned about making your code un-viewable because of a massive base64 string, why not make a separate file with your string in, and fetch it? Take this example:
Image.txt:
index.html:
Edit: Since you just updated your question, and you wish to have it displayed in another HTML tag below, just set the tag’s ID and set the SRC to it:
Happy coding!