Questions tagged [base64]

Base64 is a set of encoding schemes that represent binary data in an ASCII string format.

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 uses characters 0 to 9, A to Z and a to z to represent digits of 64-decimal numbers. The last two required digits differ between schemas. For instance, MIME (RFC 2045) uses + and / , XML names tokens use - and ., XML identifiers use _ and : and regular expressions use ! and -.

When encoding in Base64 text, 3 bytes are typically encoded into 4 characters. To encode arbitrary lengths, the padding character (=) is used. = at the end of encoded sequence means that only two bytes and == means that only one byte is encoded by the last 4 character group.

Characters outside the discussed alphabet are normally forbidden, except in MIME where they are discarded.

Base64 encoding schemes are commonly used when there is a need to encode binary data that need to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, or to store binary data in textual formats such as XML or JSON.

Useful online tools

They work without enabled JavaScript too.

11149 questions
147
votes
10 answers

Is there a way to set background-image as a base64 encoded image?

I want to change background dynamically in JS and my set of images is in base64 encoded. I try: document.getElementById("bg_image").style.backgroundImage = "url('http://amigo.com/300107-2853.jpg')"; with perfect result, yet I fail to do the…
Igor Savinkin
  • 5,669
  • 8
  • 37
  • 69
138
votes
7 answers

Should I embed images as data/base64 in CSS or HTML

To reduce the number requests on the server I have embedded some images (PNG & SVG) as BASE64 directly into the css. (Its automated in the build process) like this: background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAFWHRTb2Z0d2FyZQBBZG…
meo
  • 30,872
  • 17
  • 87
  • 123
135
votes
7 answers

convert base64 to image in javascript/jquery

I have written some code for image capturing using javascript/jquery Below is the code: function capture_image(){ alert("capture_image"); var p = webcam.capture(); webcam.save(); alert("capture complete "+p); //getting…
user2996174
  • 1,391
  • 4
  • 13
  • 20
134
votes
10 answers

RegEx to parse or validate Base64 data

Is it possible to use a RegEx to validate, or sanitize Base64 data? That's the simple question, but the factors that drive this question are what make it difficult. I have a Base64 decoder that can not fully rely on the input data to follow the RFC…
LarryF
  • 4,925
  • 4
  • 32
  • 40
131
votes
5 answers

C# Convert a Base64 -> byte[]

I have a Base64 byte[] array which is transferred from a stream which i need to convert it to a normal byte[] how to do this ?
Sudantha
  • 15,684
  • 43
  • 105
  • 161
131
votes
7 answers

What is the effect of encoding an image in base64?

If I convert an image (jpg or png) to base64, then will it be bigger, or will it have the same size? How much greater will it be? Is it recommended to use base64 encoded images on my website?
Danny Fox
  • 38,659
  • 28
  • 68
  • 94
125
votes
6 answers

Get image width and height from the Base64 code in JavaScript

I have a Base64 image encoded that you can find here. How can I get the height and the width of it?
bombastic
  • 2,961
  • 8
  • 20
  • 18
124
votes
3 answers

base64 encoded images in email signatures

I have to include some images (company logo's etc) in email signatures. I've had all sorts of issues using the embedded images produced by the email system in question (they get sent as attachments generally) and as linked images (requiring…
Peter Nunn
  • 2,110
  • 3
  • 29
  • 44
124
votes
5 answers

Code for decoding/encoding a modified base64 URL (in ASP.NET Framework)

I want to base64 encode data to put it in a URL and then decode it within my HttpHandler. I have found that Base64 Encoding allows for a '/' character which will mess up my UriTemplate matching. Then I found that there is a concept of a "modified…
Kirk Liemohn
  • 7,733
  • 9
  • 46
  • 57
119
votes
8 answers

Get Base64 encode file-data from Input Form

I've got a basic HTML form from which I can grab a bit of information that I'm examining in Firebug. My only issues is that I'm trying to base64 encode the file data before it's sent to the server where it's required to be in that form to be saved…
jordan.baucke
  • 4,308
  • 10
  • 54
  • 77
119
votes
4 answers

How can I set Image source with base64

I want to set the Image source to a base64 source but it does not work: JSfiddle.net/NT9KB the JavaScript document.getElementById("img").src = "data:image/png;base64,…
poppel
  • 1,543
  • 4
  • 17
  • 22
117
votes
4 answers

ReadFile in Base64 Nodejs

I'm trying to read an image from client side encoded in base64. How to read with nodejs? My code: // add to buffer base64 image var encondedImage = new Buffer(image.name, 'base64'); fs.readFile(encondedImage, "base64", function(err, buffer){ if…
brunocascio
  • 1,867
  • 3
  • 14
  • 21
111
votes
4 answers

Convert a string to base64 in JavaScript. btoa and atob are deprecated

I have been working on some projects in VS Code lately and suddenly started receiving notifications in my code that btoa and atob are now deprecated. I can't find any resource for this besides VS Code. If this is true, what alternative is there?
Caleb Prenger
  • 1,537
  • 4
  • 13
  • 13
111
votes
2 answers

Base64 PNG data to HTML5 canvas

I want to load a PNG image encoded in Base64 to canvas element. I have this code: