Embedding images with an encoding algorithm

AFAIK it is not possible to make TeX write binary content, so even if you would implement a base64 decode function you couldn't write it to an external file or e.g. into a \pdfobj (PDF object) directly. However, it would be possible if you have the text based base64 code in an environment (e.g. filecontents, see also the filecontents package which extends this environment) which writes it to a file where a command line tool turns it to the binary image which is then included as normal. You could call the command line tool using \write18 if -shell-escape is active or use an external script or Makefile to do this.