PNG to Base64
PNG to Base64 preserves the complete file when you encode its original bytes, including text metadata. Our downloadable tagged sample demonstrates this below. For a PNG data URL, use data:image/png;base64, plus the payload. Open the local converter.
Does an animated PNG still play after encoding?
Our original animated PNG retained its three frames and played after direct Base64 encoding; a static browser re-encode produced one frame and did not animate.
We made the same red, green and blue moving-square sample for both routes. The original file is 499 bytes with three frames. Direct encoding followed by decoding returned 499 bytes and three frames. Drawing that image into a canvas and exporting PNG in this browser produced 261 bytes and one frame. We opened both outputs together: the direct output changed colour and position while the static output stayed on the red square. These measurements apply to this specimen and this browser run, not every PNG encoder.
Not run on this device.
Watch the squares after running the comparison. The byte and frame counts below are calculated from the recovered PNG files. Playback is a separate visual observation: if the direct image does not move in your browser, record playback as not observed here.
| Item | Direct file bytes | Static re-encode |
|---|---|---|
| Measured file bytes | Not run | Not run |
| Measured frames | Not run | Not run |
| Playback in our browser run | Animated | Static |
The frame counter reads the PNG animation-control chunk; without that chunk it counts one static frame. It does not infer animation from matching bytes. This test uses only the bundled original sample, makes no conversion request, and does not accept visitor files.
Repeat our transparent PNG experiment
We created a transparent tile for this page: a green rounded rectangle with a translucent circle. The original file is 443 bytes and has dimensions of 96 by 64 pixels. Its first eight bytes are 89 50 4E 47 0D 0A 1A 0A. These are measurements of this downloadable sample, not a claim about every PNG.

The test below starts with the sample's encoded payload, decodes it into bytes, and compares each position against the original byte array bundled with this page. It also loads a PNG data URI as an image. The two results answer different questions: the comparison checks file preservation, while the image event checks rendering in your browser.
Not run on this device.
Waiting for image test.
Download decoded PNGDownload original PNG. You can compare the two downloaded files independently. The original sample's SHA-256 is:
3cb5209788937f1a2515b15275247082570459d5213977f6f078664b897005a1
A different digest would mean the file bytes differ. Matching pixels alone would not establish that its metadata, compression choices or ancillary chunks were retained. Our test is intentionally byte-based rather than a visual similarity score.
The page's optional image export changes what is being encoded. If you resize or export another format, compare the recovered bytes with that exported file, not with the original PNG. A successful round trip after export is useful, but it is a different result from preserving the input file.
Our specimen's two outputs
These boxes come from the same custom PNG. The first is its complete payload. The second adds a PNG wrapper without changing that payload. You can paste the complete URI into our decoder and download the recovered file.
iVBORw0KGgoAAAANSUhEUgAAAGAAAABACAYAAADlNHIOAAABgklEQVR4nO2cwU3EMBBFvStaoQs64EANPkM5cJ4aOGwHdJFi2OsKiaydtT1/NO9doyTSfzOOldgpBQAAAAAAsnEacZHnt5ffkpTt++ehDB86OXPwo0QcOongx4k4l04If2w+XQIIf3xOzQIIv4/WvLqHIBhLkwCq/xgtuT2VgNjXx+W/Y/X987UE4hSl+m0ndHUZe1NTeQF2IHg1EXsCpB/CNiD8kdeZgWQH2MTAPLohVAfY5GpV6wY5AdmQEmCLqlOpC2QE2OJQVCTICMiKhABzqkaFLpAQkBkEZBdgzsOA9/3dBWQHAc4gwBkEOIMAZxCQXUB1/lrlfX93AdlBgDMSAqrTMOA9/MgIyIyMgLq4GhWqX0rAylBUwpcTkBE5AXVydSpVv+zCrBnv6j2DD7Uwa0ZoalUfpgNuSbs6WklCxP0B93ZNhhQQiXsCzit2g2dla8hN+iGcgWYBdEEfrXl1dQASxufUPQQhYWw+/C0l4t9S/pJ5mroxQwQAAACAEo4r1a6cWZnr9q4AAAAASUVORK5CYII=
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABACAYAAADlNHIOAAABgklEQVR4nO2cwU3EMBBFvStaoQs64EANPkM5cJ4aOGwHdJFi2OsKiaydtT1/NO9doyTSfzOOldgpBQAAAAAAsnEacZHnt5ffkpTt++ehDB86OXPwo0QcOongx4k4l04If2w+XQIIf3xOzQIIv4/WvLqHIBhLkwCq/xgtuT2VgNjXx+W/Y/X987UE4hSl+m0ndHUZe1NTeQF2IHg1EXsCpB/CNiD8kdeZgWQH2MTAPLohVAfY5GpV6wY5AdmQEmCLqlOpC2QE2OJQVCTICMiKhABzqkaFLpAQkBkEZBdgzsOA9/3dBWQHAc4gwBkEOIMAZxCQXUB1/lrlfX93AdlBgDMSAqrTMOA9/MgIyIyMgLq4GhWqX0rAylBUwpcTkBE5AXVydSpVv+zCrBnv6j2DD7Uwa0ZoalUfpgNuSbs6WklCxP0B93ZNhhQQiXsCzit2g2dla8hN+iGcgWYBdEEfrXl1dQASxufUPQQhYWw+/C0l4t9S/pJ5mroxQwQAAACAEo4r1a6cWZnr9q4AAAAASUVORK5CYII=
The browser example makes no network request for conversion, accepts no visitor file, and does not upload the sample. The file download is built from decoded bytes locally. This test covers one deliberately simple specimen; it does not certify unknown PNG files, other applications or every possible encoding workflow.
Can changing the prefix turn JPEG into PNG?
No. The prefix describes the bytes; it does not change the file format. Export an actual PNG before labelling it as PNG. Otherwise a destination may receive an incorrectly labelled image.
Why can't I correctly encode an image to a Base64 string?
Start with file bytes, not a file path or its name. After decoding, compare with the bytes you intended to encode. Keep the wrapper separate from the payload and verify the actual image format. Our specimen gives you a known input to isolate that distinction; it cannot diagnose an unseen application.
Sources and scope
The encoding question was selected from the user-supplied discussion title “Can't correctly encode an image to base64 string”. Its comments were not supplied or read. The PNG sample, diagrams and local comparison were made for this page.
Related experiment: How to Stream Base64 into UTF-8 Text in Python — watch on YouTube.

