Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPEG image in base64 format

Tags:

image

base64

jpeg

I have a camera that send me an xml file with some tags , including a tag that represents the image in base64 format. The image is in JPEG format.

For some reason the tag that represents the image it doesn't always have the same name (for a problem of the camera)

So to detect with certainty the tag that contains the image is correct i have to now one thing :

A JPEG image in base64 format ALWAYS start with /9j/ ?

Example :

data:image/jpeg;base64,-->/9j/<--4RYQRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAgAAAAcgEyAAIAAAAUAAAAkodpAAQAAAABAAAAqAAAANQACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKQAyMDE2OjA4OjA1IDA5OjQ1OjA4AAAAAAOgAQADAAAAAf//AACgAgAEAAAAAQAAAPGgAwAEAAAAAQAAAFkAAAAAAAAABgEDAAMAAAABAAYAAAEaAAUAAAABAAABIgEbAA....
like image 492
WhiteLine Avatar asked Aug 05 '16 07:08

WhiteLine


People also ask

What is Base64 image format?

Base64 encoding is a way to encode binary data in ASCII text. It's primarily used to store or transfer images, audio files, and other media online. It is also often used when there are limitations on the characters that can be used in a filename for various reasons.

How do I make an image Base64?

Convert Images to Base64 Just select your JPG, PNG, GIF, Webp, or BMP picture or drag & drop it in the form below, press the Convert to Base64 button, and you'll get a base-64 string of the image. Press a button – get base64. No ads, nonsense, or garbage. Drag and drop your image here!

Can we convert image to Base64?

The Image encoding tool supports loading the Image File to transform to Base64. Click on the Upload Image button and select File. Image to Base64 Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.


1 Answers

Jpeg file format (as many others) can be identified by magic number. For JPEG the magic number is ff d8 ff at offset 0. If you encode this to Base64, you'll always get /9j/.

Additional note: since Base64 converts group of 3 data bytes to 4 bytes (ASCII), this will work for any magic number with length and offset multiple of 3 bytes. If the length of magic number is not multiple of 3, the last group of 4 Base-64 encoded characters will change depending on the data immediately following the magic number.

https://en.wikipedia.org/wiki/JPEG

https://en.wikipedia.org/wiki/List_of_file_signatures

like image 77
nevermind Avatar answered Sep 28 '22 09:09

nevermind