Created
June 11, 2020 11:44
Show graphical manipulation commands in moodle.sty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% | |
\makeatletter | |
\renewcommand\moodle@includegraphics@int@int[2][]{% | |
\bgroup% The grouping is to localize the changes caused by \setkeys. | |
\message{moodle.sty: Processing \string\includegraphics[#1]{#2} for HTML...^^J} | |
\setkeys*{moodle@includegraphics}{#1}% | |
% Height or width should be given in TeX dimensions like cm or pt or in, | |
% and are converted to pixels for web use using the ppi key. | |
% TO DO: Can we modify \includegraphics to accept height or width in | |
% pixels? | |
% TO DO: What about \includegraphics[scale=0.7] ? | |
% Other keys: keepaspectratio=true|false, angle (rotation), clip & trim | |
\ifnum\moodle@graphics@height@pixels=0\relax | |
\ifnum\moodle@graphics@width@pixels=0\relax | |
% No size specified. Default to height of 200 pixels. | |
\def\moodle@graphics@geometry{x200}% | |
\def\moodle@graphics@htmlgeometry{}% | |
\else | |
% Width only specified. | |
\edef\moodle@graphics@geometry{\number\moodle@graphics@width@pixels}% | |
\edef\moodle@graphics@htmlgeometry{width=\number\moodle@graphics@width@pixels}% | |
\fi | |
\else | |
\ifnum\moodle@graphics@width@pixels=0\relax | |
% Height only specified. The `x' is part of the syntax. | |
\edef\moodle@graphics@geometry{x\number\moodle@graphics@height@pixels}% | |
\edef\moodle@graphics@htmlgeometry{height=\number\moodle@graphics@height@pixels}% | |
\else | |
% Height and width both specified. The `!' is part of the syntax. | |
\edef\moodle@graphics@geometry{\number\moodle@graphics@width@pixels x\number\moodle@graphics@height@pixels!}% | |
\edef\moodle@graphics@htmlgeometry{width=\number\moodle@graphics@width@pixels\otherspace height=\number\moodle@graphics@height@pixels}% | |
\fi | |
\fi | |
%First, convert it to PNG | |
\edef\cmdline{\htmlize@imagemagick@convert\otherspace #2 -resize \moodle@graphics@geometry\otherspace #2.png}% | |
\message{moodle.sty: Converting '#2' to PNG...^^J}% | |
\message{command is: \cmdline ^^J} | |
\expandafter\immediate\expandafter\write18\expandafter{\cmdline}% | |
%Next, convert the PNG to base64 encoding | |
\def\cmdline{\openssl\otherspace enc -base64 -in #2.png -out #2.enc}% | |
\message{command is: \cmdline ^^J} | |
\expandafter\immediate\expandafter\write18\expandafter{\cmdline}% | |
\message{command is: \cmdline} | |
%Now, save that base64 encoding in a TeX macro | |
\def\moodle@newpic@baselxiv{}% | |
\message{moodle.sty: Reading base64 file '#2.enc'...^^J}% | |
\openin\baseLXIVdatafile=#2.enc\relax | |
\savebaselxivdata@recursive | |
\closein\baseLXIVdatafile | |
\xa\global\xa\let\csname picbaselxiv@graphics@#2\endcsname=\moodle@newpic@baselxiv% | |
\edef\htmlize@imagetag{<IMG \moodle@graphics@htmlgeometry\otherspace SRC="data:image/png;base64,\csname picbaselxiv@graphics@#2\endcsname">}% | |
\xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}% | |
\message{moodle.sty: <IMG> tag inserted.^^J}% | |
\egroup | |
% Now we re-insert the code to get the HTMLizing going again. | |
\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook | |
} | |
\makeatother | |
\endinput | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment