Skip to content

Instantly share code, notes, and snippets.

@dohyunkim
Last active March 2, 2026 01:00
Show Gist options
  • Select an option

  • Save dohyunkim/4852189887355d461c7ca5a899f91bba to your computer and use it in GitHub Desktop.

Select an option

Save dohyunkim/4852189887355d461c7ca5a899f91bba to your computer and use it in GitHub Desktop.
image masking with luamplib
\documentclass[a5paper]{article}
\usepackage{luamplib,graphicx}
\directlua{
tex.print(-2,{
token.create"graphicspath",
token.new(0,1), token.new(0,1),
kpse.var_value"TEXMFDIST", "/doc/generic/pgf/images/",
token.new(0,2), token.new(0,2),
})
}
\pagestyle{empty}
\begin{document}
\begin{mplibgroup}{mymask}[asgroup="masking"]
%\mpfig
% draw btex
\includegraphics[decodearray={1 0},width=200bp]{brave-gnu-world-logo-mask}
% etex;
%\endmpfig
\end{mplibgroup}
\mpfig
picture pic;
pic = btex \includegraphics[width=200bp]{brave-gnu-world-logo} etex;
bboxmargin := 10;
fill bbox pic
withshadingmethod "linear"
withshadingvector (3.2, 0)
withshadingstep(
withshadingfraction 2/4
withshadingcolors (red,green)
)
withshadingstep(
withshadingfraction 1
withshadingcolors (green,blue)
)
;
draw pic
withmaskinggroup "mymask"
;
\endmpfig
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment