I'm always wondered where to find rules to encode known file formats, for example: .jpg, .png, .mpg programmatically. How to write these binary formats? Some years ago, when I surfed phpBB scripts, I found that they for example don't use any gd or imagemagick, they write it in binary way. Not only for php, but for other languages as well?
2 Answers
- The Wikipedia Article seems to have a pretty good rundown on the PNG format's internal structure
- The JPEG standard (PDF) - read the Wikipedia article on JPG as an introduction
- Here's a nice one for GIF: GIF spec and the official one (much more heavy reading): Gif89a
Video encoding is a whole different issue, and orders of magnitude more complex... Although I imagine one can already spend a lot of time understanding the JPEG format in depth.
Usually, looking up the desired format's article in Wikipedia will either give you the format definition, or a link to the specification.
Comments
Do you mean the "data:" URI specification? http://en.wikipedia.org/wiki/Data_URI_scheme
<img src="data:image/gif;base64,AAAA" alt="blank">
Simply base64 encode your image, set the correct mime type, and have fun.
Note that this defeats browser caching of images, and base64-encoding leads to roughly 4/3 size increase of the data transfer required. So it's not an obvious performance win.