/    Sign up×
Community /Pin to ProfileBookmark

How to embed not a link but the picture itself into html source?

Assume I have an element like

`<img src=”https://www.foobar.com/mysmallpic.png” ……>samplepic</img>`

Now I want to avoid a linking to a picture source on an external server.

Instead I want to embed the few KB of the picture directly into HTML source code. I can imagine that there is a method similar to

`<img src=x’21315112A56CED……58889EFED’ ……>samplepic</img>`

or alternatively with variable:

“`
mypic=x’21315112A56CED……58889EFED’ ;

<img src=mypic …..>samplepic</img>
“`

x’…’ means the hexadecimal binary content (ANSI or Unicode ?) of the picture source.

Is this somehow possible?

Peter

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumSep 11.2020 — Yes, this can be done by use of a data URL and the base64 format:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

Try to find an online converter to convert your image to base64.

BTW: The img tag has no closing tag, thus your HTML is not valid.
×

Success!

Help @pstein spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...