A commonly asked question on this site is how to embed images directly in a .tex source file, without the need for the image to exist in a separate file. Examples of such questions (often marked as duplicate) are
- Include source code of pdf picture directly into LaTeX file
- Embedding images with an encoding algorithm
- Possible to Embed Base64 Encoded Images in TeX Documents?
- Directly embedded images
- Embed image data (png or pdf) inside tex document
- ...
Unfortunately, the answers are all quite a bit outdated. In particular,
- Many users responded (years ago) that "the user should simply not want this" and send multiple files as a zip/tar archive instead. However, in this time and age where automatic generation of .tex file becomes more frequent, and single-file text-only generation is much easier (especially when using predefined frameworks) than multifile and/or binary, that argument no longer holds.
- A package providing such functionality https://gist.github.com/mikeashley/258731 no longer exists. Another package https://github.com/zerotoc/pdfinlimg provides this functionality but only for bitmap images (png/jpg), not for svg/eps/pdf/other vector formats, and encodes it as HEX which is pretty wasteful compared to base64.
Therefore I would like to reopen this question and ask this again: how can one create a command \includebase64image such that
\includebase64image{png}{iVBORw0KGgokIA...}
\includebase64image{pdf}{weEGE2ewFWE58q...}
yields the result of \includegraphicx{a file with content type #1 and contents #2}
, namely the image whose content and type are given, appearing at the current location in the generated PDF file?