summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-04-05 21:13:04 +0000
committerKarl Berry <karl@freefriends.org>2019-04-05 21:13:04 +0000
commit398a9e99b782bc15f1c5cecfb762159b712de603 (patch)
tree81df2ccd7a66d6b5acf9ea478c2c3429de3e9f7e
parent972b985364ffd1dc9bb359d076879a270ca3575c (diff)
luaimageembed (5apr19)
git-svn-id: svn://tug.org/texlive/trunk@50788 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE21
-rw-r--r--Master/texmf-dist/doc/lualatex/luaimageembed/README.md41
-rw-r--r--Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty85
-rwxr-xr-xMaster/tlpkg/bin/tlpkg-ctan-check2
-rw-r--r--Master/tlpkg/tlpsrc/collection-luatex.tlpsrc1
-rw-r--r--Master/tlpkg/tlpsrc/luaimageembed.tlpsrc0
6 files changed, 149 insertions, 1 deletions
diff --git a/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE b/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE
new file mode 100644
index 00000000000..aa53876ce8b
--- /dev/null
+++ b/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2017 Christian C. Sachs
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Master/texmf-dist/doc/lualatex/luaimageembed/README.md b/Master/texmf-dist/doc/lualatex/luaimageembed/README.md
new file mode 100644
index 00000000000..0ed617ea34e
--- /dev/null
+++ b/Master/texmf-dist/doc/lualatex/luaimageembed/README.md
@@ -0,0 +1,41 @@
+# luaimageembed
+
+LuaTeX package to embed images directly as base64-encoded strings into the document. This can be useful, e.g. to package a document with images into a single TeX file, or with automatically generated graphics.
+
+The image files will be decoded, written to a temporary directory, and cleaned up afterwards.
+
+Use at your own risk.
+
+## Commands
+
+Three commands are wrapped to allow for use with base64-encoded images:
+
+- `\includegraphicsembedded` (`\includegraphics`)
+- `\pgfdeclareimageembedded` (`\pgfdeclareimage`)
+- `\pgfimageembedded` (`\pgfimage`)
+
+Each takes the base64-encoded image data instead of the filename; see the example below. Supported are `png`, `jpg`, `jb2` and `pdf` images.
+
+## Example
+
+```latex
+\documentclass{scrartcl}
+
+\usepackage{luaimageembed}
+\usepackage{graphicx}
+
+\begin{document}
+\includegraphicsembedded[width=4cm]{%
+iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAAAAABzQ+pjAAAAFElEQVQI12P4z/Cf4f9/BgYGBgYA
+IOsD/UqPmwUAAAAASUVORK5CYII=
+}
+\end{document}
+```
+
+## Version
+
+0.1 (alpha)
+
+## License
+
+MIT
diff --git a/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty b/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty
new file mode 100644
index 00000000000..184c5fbb0b1
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty
@@ -0,0 +1,85 @@
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{luaimageembed}[2017/08/12 luaimageembed alpha version 0.1]
+
+% Copyright Christian C. Sachs, MIT licensed
+
+\RequirePackage{luacode}
+
+% no options so far
+
+\begin{luacode*}
+
+image_counter = 0
+image_list = {}
+image_tmpdir = nil
+
+function add_image(data)
+ if image_tmpdir == nil then
+ image_tmpdir = os.tmpdir()
+ end
+
+ local ltn12 = require("ltn12")
+ local mime = require("mime")
+
+ local file_name = image_tmpdir .. "/" .. "image" .. image_counter
+ image_counter = image_counter + 1
+
+ ltn12.pump.all(
+ ltn12.source.string(data),
+ ltn12.sink.chain(
+ mime.decode("base64"),
+ ltn12.sink.file(io.open(file_name, "a"))
+ )
+ )
+
+ local file = io.open(file_name, "rb")
+
+ local magic = file:read(2)
+ file:close()
+
+ local new_extension = "error"
+
+ if magic == "\x89\x50" then
+ new_extension = "png"
+ elseif magic == "\xff\xd8" then
+ new_extension = "jpg"
+ elseif magic == "\x97\x4a" then
+ new_extension = "jb2"
+ elseif magic == "\x25\x50" then
+ new_extension = "pdf"
+ else
+ error("Unsupported image data passed")
+ end
+
+ local old_file_name = file_name
+ local file_name = file_name .. "." .. new_extension
+ texio.write_nl('term', "magic=" .. magic)
+ texio.write_nl('term', "output_filename=" .. file_name)
+
+ os.rename(old_file_name, file_name)
+
+ table.insert(image_list, 1, file_name)
+
+ return file_name
+
+end
+
+function cleanup_images()
+ for i = 1, #image_list do
+ os.remove(image_list[i])
+ end
+
+ if image_tmpdir ~= nil then
+ lfs.rmdir(image_tmpdir)
+ end
+end
+
+luatexbase.add_to_callback("finish_pdffile", cleanup_images, "Removes temporary images and folder again")
+
+\end{luacode*}
+
+\newcommand{\includegraphicsembedded}[2][]{\includegraphics[#1]{\directlua{tex.print(add_image([[#2]]))}}}
+\newcommand{\pgfdeclareimageembedded}[3][]{\pgfdeclareimage[#1]{#2}{\directlua{tex.print(add_image([[#3]]))}}}
+\newcommand{\pgfimageembedded}[2][]{\pgfimage[#1]{\directlua{tex.print(add_image([[#2]]))}}}
+
+\endinput
diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check
index afe728c0114..2d29b8acd21 100755
--- a/Master/tlpkg/bin/tlpkg-ctan-check
+++ b/Master/tlpkg/bin/tlpkg-ctan-check
@@ -422,7 +422,7 @@ my @TLP_working = qw(
ltxkeys ltxmisc ltxnew ltxtools
lua-alt-getopt lua-check-hyphen lua-visual-debug
lua2dox luabibentry luabidi luacode luahyphenrules
- luaindex luainputenc luaintro lualatex-doc lualatex-doc-de
+ luaimageembed luaindex luainputenc luaintro lualatex-doc lualatex-doc-de
lualatex-math lualatex-truncate lualibs
luamesh luamplib luaotfload luapackageloader luarandom
luasseq luatex85 luatexbase luatexja luatexko luatextra
diff --git a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
index fd0027059f0..efa7a5cce72 100644
--- a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
+++ b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
@@ -19,6 +19,7 @@ depend lua-visual-debug
depend lua2dox
depend luacode
depend luahyphenrules
+depend luaimageembed
depend luaindex
depend luainputenc
depend luaintro
diff --git a/Master/tlpkg/tlpsrc/luaimageembed.tlpsrc b/Master/tlpkg/tlpsrc/luaimageembed.tlpsrc
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/Master/tlpkg/tlpsrc/luaimageembed.tlpsrc