image tool
Image to base64
Embedding a picture in text is easy. Knowing whether you should is the harder part, so this shows the arithmetic as it goes: bytes in, base64 characters out, what it costs gzipped over the wire, and where that sits against the size at which build tools stop inlining.
Runs on your device. Nothing is uploaded.
Loading the tool…
How to use it
- 1
Drop the image
Small ones. Icons, logos and simple graphics are what this technique is for.
- 2
Read the ledger
File bytes, base64 characters, the full pasted length and the growth, with the padding arithmetic spelled out underneath.
- 3
Check the budget bar
It measures your string against 8,192 bytes, the size at which build tools switch from inlining a file to emitting it. Over that line, host the file instead.
- 4
Pick the wrapper and copy
Data URI, a CSS rule, an image tag, Markdown, a JSON string or an SVG image element. One button copies whichever is showing.
The arithmetic, shown rather than asserted
Base64 writes every three bytes as four characters and pads the last group out to a multiple of four, so a file of n bytes becomes exactly four times the ceiling of n over three characters. That is a third larger, always, before the data URI prefix. The ledger prints that calculation with your actual numbers in it, including how many padding characters you ended up with, because a rule of thumb you can check is worth more than one you have to trust.
Why the gzipped number matters more
The raw growth of a third is the figure everyone quotes, and it is the wrong one to make a decision on. Your stylesheet is compressed before it crosses the network, and gzip claws most of that overhead back, because base64 output has only 64 distinct characters in it. The tool compresses the string in the browser and shows you what it really costs on the wire against the file served on its own. The remaining argument against inlining is not size, it is caching.
The 8,192 byte line
Build tools have converged on the same threshold. Webpack's asset modules inline anything under 8,192 bytes as a data URI and emit a separate file above it, and other bundlers default to something near it. It is a reasonable line for a hand written stylesheet too, which is why the budget bar measures against it. Under the line, embedding saves a request and costs almost nothing. Over it, you are pushing uncacheable bytes into every page that carries the document.
An SVG does not want base64 at all
An SVG is already text, mostly ASCII, and base64 makes it a third longer for no reason. Escaping only the handful of characters a URL and an attribute cannot carry gives a shorter string that every browser reads, and it stays readable in the source. That variant appears as its own tab as soon as an SVG is loaded, with the character counts side by side so you can see the difference rather than take it on faith.
Limits
- Base64 makes the text about a third larger than the file, and the data URI prefix adds a little more on top.
- Very large images produce strings too long to work with comfortably in a stylesheet or a template.
- Some email clients block or strip data URIs, which is the opposite of what people usually hope. Test before you send to a list.
- The gzipped figure needs the browser's compression API. Where that is missing, only the raw character counts are shown.
- A data URI cannot be cached on its own. It is re-sent with every copy of the document that carries it.
What it does not do
- It does not host your image anywhere, and there is no link to share.
- It does not compress or resize the image first. Do that before you convert, or the string is bigger than it needs to be.
- It does not minify or optimise an SVG before encoding it.
Questions people ask
How big can the image be?
Practically, keep the finished string under about eight thousand characters, which is what the budget bar measures. There is no hard limit in the browser, but a longer data URI makes a stylesheet painful to work with, and past that point hosting the file and linking to it is almost always the better trade.
Why is the gzipped number so much smaller?
Because base64 output uses only 64 distinct characters, which compresses well, and your stylesheet is gzipped or brotli compressed before it is sent. Most of the notorious 33 percent overhead disappears on the wire. What does not disappear is that the bytes ride along with the document every time instead of being cached separately.
Do email clients support data URIs?
Support is uneven and several clients block them outright, which catches people out because email is the case they usually reach for this to solve. Test with the clients your audience actually uses before you rely on it for a campaign. Hosted images with a sensible fallback are still the safer route.
Does it work for SVG?
Yes, and better than you would expect. An SVG converts like any other file, but a URL encoded variant also appears, which escapes only what a URL cannot hold rather than encoding everything. That is usually shorter than the base64 version. Remember an SVG can also be pasted inline directly, avoiding the wrapper altogether.
Should I use this for photographs?
No. A photograph produces an enormous string, cannot be cached on its own, and is re-downloaded with every page view. The budget bar will say so. Host the file, link to it, and let the browser cache it. This technique is for icons and small graphics where the request itself is the cost.
Can I go the other way?
Yes. Open the advanced panel and paste a data URI into the decode box. It reads the media type, decodes the payload, tells you how many bytes came out of how many characters, shows a preview if it is an image, and offers it back as a file with a sensible extension.
Is my image uploaded?
No. The file is read by your browser, encoded in this tab and never sent anywhere. That matters more than it sounds for the ordinary cases this gets used for: a product shot before launch, a screenshot with customer data in it, or somebody's photograph you were trusted with.
Build the thing this image goes in
Take what you made here into forms.
Create a form with OneCraftRelated tools
- Image compressorCompress to WebP or JPEG and compare the result against the original under a divider you drag. Or ask for a size in KB. Nothing is uploaded.
- Convert an imageSee your own picture measured in PNG, JPEG and WebP before you choose, then convert. Transparency is handled deliberately, and HEIC is explained.
- Image resizerResize a batch of images to an exact width, height or percentage. Fit, fill or stretch, with a stepped downscale that keeps detail. Nothing is uploaded.
Written and checked by the OneCraft team. Last checked .