Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to base64 encode images before transmitting? [duplicate]

Tags:

http

php

base64

Possible Duplicate:
What is the use of base 64 encoding?

I've seen many code fragments that base64 encode images before transmitting over HTTP protocol.

I am wondering why do we need it?

like image 691
Pentium10 Avatar asked Mar 10 '10 17:03

Pentium10


People also ask

Why do we need to encode to Base64?

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. This is to ensure that the data remain intact without modification during transport.

Should I use Base64 for images?

Base64 is very versatile in technology, but you should try not to use it as part of your HTML or CSS files unless you have a very good reason. Base64 is only useful for very small images.

Does Base64 encoding reduce image quality?

Encoding to/from Base64 is completely lossless.

How does Base64 work for images?

Browser takes the image/png part and knows that the data following it will be the bytes of a png image. It then sees base64, and knows that the next blob will need to be base64 decoded, before it can then be decoded by its png decoder. It converts the base64 string to bytes.


1 Answers

It's not necessary, but it enables you to embed images without performing additional HTTP requests (where, in some cases, it's not possible or permitted).

like image 121
Adrian Avatar answered Sep 28 '22 05:09

Adrian