texlive[50788] Master: luaimageembed (5apr19)

commits+karl at tug.org commits+karl at tug.org
Fri Apr 5 23:13:05 CEST 2019


Revision: 50788
          http://tug.org/svn/texlive?view=revision&revision=50788
Author:   karl
Date:     2019-04-05 23:13:04 +0200 (Fri, 05 Apr 2019)
Log Message:
-----------
luaimageembed (5apr19)

Modified Paths:
--------------
    trunk/Master/tlpkg/bin/tlpkg-ctan-check
    trunk/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/lualatex/luaimageembed/
    trunk/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE
    trunk/Master/texmf-dist/doc/lualatex/luaimageembed/README.md
    trunk/Master/texmf-dist/tex/lualatex/luaimageembed/
    trunk/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty
    trunk/Master/tlpkg/tlpsrc/luaimageembed.tlpsrc

Added: trunk/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/lualatex/luaimageembed/LICENSE	2019-04-05 21:13:04 UTC (rev 50788)
@@ -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.

Added: trunk/Master/texmf-dist/doc/lualatex/luaimageembed/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/luaimageembed/README.md	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/lualatex/luaimageembed/README.md	2019-04-05 21:13:04 UTC (rev 50788)
@@ -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


Property changes on: trunk/Master/texmf-dist/doc/lualatex/luaimageembed/README.md
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty	2019-04-05 21:13:04 UTC (rev 50788)
@@ -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


Property changes on: trunk/Master/texmf-dist/tex/lualatex/luaimageembed/luaimageembed.sty
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check	2019-04-05 21:12:21 UTC (rev 50787)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check	2019-04-05 21:13:04 UTC (rev 50788)
@@ -422,7 +422,7 @@
     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

Modified: trunk/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc	2019-04-05 21:12:21 UTC (rev 50787)
+++ trunk/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc	2019-04-05 21:13:04 UTC (rev 50788)
@@ -19,6 +19,7 @@
 depend lua2dox
 depend luacode
 depend luahyphenrules
+depend luaimageembed
 depend luaindex
 depend luainputenc
 depend luaintro

Added: trunk/Master/tlpkg/tlpsrc/luaimageembed.tlpsrc
===================================================================


More information about the tex-live-commits mailing list