Skip to main content
L
Loopaloo
Buy Us a Coffee
All ToolsImage ProcessingAudio ProcessingVideo ProcessingDocument & TextPDF ToolsCSV & Data AnalysisConverters & EncodersWeb ToolsMath & ScienceGames
Guides & BlogAboutContact
Buy Us a Coffee
L
Loopaloo

Free online tools for developers, designers, and content creators. Your files are processed in your browser and are never uploaded - no accounts required. A few network utilities (like What's My IP and Currency Converter) call public APIs to do their job and say so on their pages.

support@loopaloo.com

Tool Categories

  • Image Tools
  • Audio Tools
  • Video Tools
  • Document & Text
  • PDF Tools
  • CSV & Data
  • Converters
  • Web Tools
  • Math & Science
  • Games

Company

  • About Us
  • Contact
  • Blog
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

Support

Buy Us a Coffee

© 2026 Loopaloo. All rights reserved. Built with privacy in mind.

Privacy|Terms|Disclaimer
  1. Home
  2. Image Processing
  3. Image to Base64
Add to favorites

Image to Base64

Turn an image into a data URL whose payload is decoded again and compared byte for byte with the file, with the media type taken from the file's own signature rather than its extension and the size cost of embedding stated in full.

Edits stay in your browserMore image processingJump to full guide

Initializing in your browser…

You might also like

Image Format Converter

Convert between the formats a browser can really write, then open the output and name the format its first bytes say it is. AVIF, BMP and GIF are disabled because a canvas returns a PNG for all three.

Image Resizer

Resize with the filter named (Lanczos, Mitchell, Catmull-Rom, bilinear, box or nearest) and the option to average LIGHT rather than stored bytes, which is worth 1.24 stops on a detailed picture.

Image Cropper

Whole-pixel crops with the rectangle typed or dragged, checked by decoding the output and comparing it with the pixels that went in. Quarter turns and mirrors are exact permutations, so nothing is clipped.

Image to Base64: a worked example

A 16 by 16 PNG of 138 bytes, saved under the name photo.jpg.

Input

photo.jpg · 138 bytes on disk
What Image to Base64 produces

What the page reports

First bytes      89 50 4E 47 0D 0A 1A 0A
Signature says   PNG
Browser said     image/jpeg   (from the NAME)
Data URL uses    image/png    (from the BYTES)

Round trip       184 base64 chars decoded again:
                 all 138 bytes identical

A browser fills a file’s type in from its extension, so a renamed PNG is handed over as image/jpeg and the data URL says so. The type here comes from the first bytes instead. The round trip is the other half: the payload is decoded again and compared with the file, so "this string is your image" is a check rather than a claim.

What is Image to Base64?

Turn an image into a data URL that decodes back to the exact bytes of your file, with that check performed and reported rather than assumed. The media type comes from the file's own signature rather than from its extension, and the size cost of embedding is stated in full.

How to use

  1. 1Upload an image
  2. 2Read the verification panel: it decodes the payload again and says whether all the bytes match
  3. 3Choose an output shape: the data URL, the raw payload, CSS, HTML or Markdown
  4. 4Copy or download the text
  5. 5Only if you want a smaller picture, set a maximum width, and read what the re-encode cost

Where this helps

  • Embedding a small icon in CSS

    One fewer request for a sprite or a small background, with the size cost of doing it shown before you commit.

  • An image inside a self-contained HTML file

    A report or an email template that has to travel as one file, with the payload verified before it goes in.

  • Checking what a file really is

    The first bytes and the format they name, beside the type the browser guessed from the extension.

  • An inline SVG background

    The percent-encoded form, which is shorter than base64 and still readable in the stylesheet.

Key features

  • The payload decoded again and compared byte for byte with what went in, with the verdict on the page
  • The media type taken from the file's own first bytes, with the signature printed and any disagreement with the extension named
  • The exact size cost: file bytes, payload characters, whole URL length and the overhead as a percentage
  • Five output shapes, plus a percent-encoded form for SVG, which is smaller than base64 for XML
  • A resize that says plainly it produces a different picture, with SSIM, PSNR and the worst channel reported
  • Whether the quality setting does anything, measured by encoding at both ends of the range rather than assumed
  • The preview drawn from the data URL itself, so what you see is what the string produces
  • Works on files of several megabytes; a 9000 by 6000 photograph encodes without trouble

Tips & best practices

  • Leave the resize at zero unless you want a different picture. It is the only setting under which the string decodes back to your file, and the page reports that check either way.
  • If the file came from somewhere else, look at the signature line. A file whose name and contents disagree is common enough after a rename, and the data URL now carries the truth rather than the extension.
  • For an SVG use the percent-encoded form rather than base64. It is usually shorter and you can read and edit it in place.
  • A data URL is roughly a third larger than the file and cannot be cached on its own. Below about 4 KB that trade is usually worth one fewer request; well above it, usually not.

Examples

  • A CSS background with no extra request

    Upload a small PNG, pick the CSS form, and paste the declaration. The page has already decoded the payload again and confirmed it is byte for byte the file you gave it.

  • Catching a renamed file

    A PNG saved as photo.jpg: the browser calls it image/jpeg, the first bytes say 89 50 4E 47, and the data URL is written as image/png with the disagreement named on the page.

How it works

A base64 tool makes one claim: that the string decodes back to the file. That is decidable, and the way to settle it is to decode the string again and compare byte for byte, which this page does and reports. On every fixture in the test suite, from a 138 byte PNG to a 9000 by 6000 JPEG, the payload decodes to a file identical to the one on disk, confirmed both here and independently by Python's own `base64` module with validation on. Reporting that the encoding is CORRECT is worth as much as reporting a fault would have been, because it is the thing nobody checks.

What was wrong sat around the encoding. The media type in a data URL used to come from `File.type`, and a browser fills that in from the file EXTENSION rather than from the contents. A PNG renamed to `.jpg` was therefore handed out as `data:image/jpeg;base64,iVBORw0KGgo...`, a JPEG declaration in front of PNG bytes. The type now comes from the file's own first bytes through a signature sniffer that knows seven formats, the first bytes are printed on the page, and when the name and the signature disagree the page says so with both values. Browsers sniff and cope; a strict consumer, a server that trusts the declared type, or a content policy that filters on it does not.

The cost of embedding is stated rather than left to be discovered. Base64 is exactly four characters for every three bytes, so a data URL is about a third larger than the file it carries, and the page shows the file size, the payload length, the whole URL length and the overhead as a percentage. It also says the part that is not arithmetic: an embedded image cannot be cached separately from the document it sits in, which is the trade being made for one fewer request.

Resizing before encoding is now honest about what it is. Any resize decodes the picture, scales it and encodes a NEW one, so the string no longer represents your file, and the page says exactly that with the new dimensions and the format. The scaling goes through this project's resampler with the filter named and cited rather than through a bare `drawImage`, whether the quality setting does anything is MEASURED by encoding at both ends of the range (it does nothing at all for PNG, and the page says so rather than leaving a useful-looking control that is inert), and the cost is reported as SSIM, PSNR, the worst channel difference and the share of pixels that moved.

Five output shapes are offered, all carrying the same payload: the whole data URL, the raw RFC 4648 payload, a CSS `background-image` declaration, an `<img>` tag and Markdown. For an SVG a sixth appears, because RFC 2397 allows the data to be percent-encoded instead of base64, and for XML that is both smaller (base64 costs a flat third; percent-encoding costs only the characters that need escaping) and readable in the stylesheet. The preview is drawn from the data URL itself rather than from the file, so what you see is what the string produces. Nothing is uploaded.

Frequently asked questions

Does the string really decode back to my file?

Yes, and the page checks rather than claiming. After encoding, the payload is decoded again and compared byte for byte with what went in, and the result is reported either way. In the test suite the same check is done independently by Python, on files from 138 bytes to 1.5 MB, and every one matched.

Why does the media type not match my file extension?

Because the extension can be wrong. A browser fills in a file's type from its name, so a PNG renamed to .jpg is handed over as image/jpeg. This page reads the first bytes instead and writes what the file actually is, printing both and naming the disagreement when there is one.

How much bigger is a data URL than the file?

Base64 is four characters for every three bytes, so about 33 percent, plus the header. A 613 KB JPEG becomes 837,084 characters. The page shows all four numbers. The second cost is not size: an embedded image cannot be cached separately from the page it sits in.

Should I resize before encoding?

Only if you want a different picture. A resize decodes, scales and encodes again, so the string is no longer your file, and the page says so with the new size and format and reports what the re-encode cost in SSIM and PSNR. With the width at zero nothing is touched.

Why is the quality control disabled?

Because nothing is being encoded again. It becomes active when a resize is set, and even then the page measures whether it does anything: PNG ignores it entirely, giving the identical byte count at 0.1 and at 1.0, and the page says that instead of leaving a control that looks useful and is not.

Is there a size limit?

Practically, your browser's memory. A 9000 by 6000 photograph encodes here without trouble. The thing that bites first is usually the page you paste it into: a two megabyte string in a stylesheet is a two megabyte stylesheet.

Related tools and how they differ

  • Base64 Encoder/Decoder: The same encoding for text and arbitrary files, with both alphabets and a decode check.
  • Image Compressor: Make the file smaller before embedding it, since a data URL costs a further third.

Private by design

Images are decoded, edited, and exported entirely inside this browser tab. No originals, exports, or metadata are uploaded.