macro for images with alt and title generated from the EXIF metadata v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 02 Dec 2018 02:18:54 +0100
branchv_0
changeset 174 c78dfa0603c9
parent 173 d248aa5da038
child 175 c079bc35b9b8
macro for images with alt and title generated from the EXIF metadata
relpipe-data/makra/img.xsl
relpipe-data/screenshots.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relpipe-data/makra/img.xsl	Sun Dec 02 02:18:54 2018 +0100
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="2.0"
+				xmlns="http://www.w3.org/1999/xhtml"
+				xmlns:h="http://www.w3.org/1999/xhtml"
+				xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
+				xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace"
+				xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
+				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+				xmlns:fn="http://www.w3.org/2005/xpath-functions"
+				xmlns:svg="http://www.w3.org/2000/svg"
+				xmlns:xs="http://www.w3.org/2001/XMLSchema"
+				exclude-result-prefixes="fn h s k m xs">
+	
+	<!--
+		Images
+		******
+		Generates an XHTML img tag in a paragraph for given image.
+		Title and Alt are filled with the EXIF comment field.
+		Requires a command line tool: exiv2
+		*
+		@src path to the image file relative to the input directory (where web.conf resides)
+	-->
+	<xsl:template match="m:img">
+		<xsl:variable name="script">
+			<m:skript jazyk="bash" výstup="xml">
+				DIR=$(dirname "$XWG_STRANKA_SOUBOR");
+				DIR="$DIR/../vstup"
+				cd "$DIR";
+				
+				<![CDATA[echo -n '<metadata>';]]>
+				
+				<![CDATA[echo -n '<description>';]]>
+				exiv2 "<xsl:value-of select="@src"/>" | <![CDATA[perl -ne 'if (/Exif comment\s*:\s*(.*)/) { print "$1"; }' ]]> | <m:escape-xml/>
+				<![CDATA[echo -n '</description>';]]>
+				
+				<![CDATA[echo -n '</metadata>';]]>
+			</m:skript>
+		</xsl:variable>
+
+		<xsl:variable name="scriptResult">
+			<xsl:apply-templates select="$script/node()"/>
+		</xsl:variable>
+		
+		<p>
+			<!--
+				TODO: check whether the thumbnail exists and if yes, disply it and link to the full image.
+			-->
+			<a href="{@src}">
+				<img src="{@src}"
+					 alt  ="{$scriptResult/h:metadata/h:description}" 
+					 title="{$scriptResult/h:metadata/h:description}"/>
+			</a>
+		</p>
+		
+	</xsl:template>
+
+</xsl:stylesheet>
+
--- a/relpipe-data/screenshots.xml	Sun Dec 02 02:18:23 2018 +0100
+++ b/relpipe-data/screenshots.xml	Sun Dec 02 02:18:54 2018 +0100
@@ -25,9 +25,8 @@
 			There are some examples:
 		</p>
 		
-		<p>
-			<img src="img/kde-cli-tabular-1.png" alt="Relational pipes in KDE: CLI + Tabular"/>
-		</p>
+		<m:img src="img/kde-cli-tabular-1.png"/>
+
 	</text>
 
 </stránka>