On 16-2-2012 07:43, Mari Voipio wrote:
Hello all,
I'm trying to do something that should be possible and I think
"variables" is the answer, I just can't figure out how.
I have a pile of photos (jpg) in a directory and the assumption is
that they are all the same size and there's a spot for the photo on a
layer at the top of the page. I already found out how I can get
ConTeXt to draw the layer separately for each page (at
http://wiki.contextgarden.net/layers#Use_dynamic_content), but I think
I need a "variables for dummies" page...
This time I'm not too picky, the images can be used randomly or in the
order they are in the directory and then cycled, I'd just like to use
more than one (and I'm so not doing every page by hand).
So, if I have
photo1.jpg
photo2.jpg
photo3.jpg
photo4.jpg
and \dorecurse{10}{insert random photo here}, how do I do it?
More fancy ...
\startluacode
local files = { }
function document.collectgraphics(pattern)
files = table.merged(files,dir.glob(pattern))
files = table.unique(files)
table.sort(files)
logs.report(string.format("graphics: %s",table.concat(files," ")))
end
function document.choosegraphics()
if #files > 0 then
context(table.remove(files, math.random(1,#files)) or "dummy")
else
context("dummy")
end
end
\stopluacode
\def\CollectGraphics[#1]{\ctxlua{document.collectgraphics("#1")}}
\def\ChooseGraphic {\ctxlua{document.choosegraphic()}}
\CollectGraphics[*.png]
\CollectGraphics[*.jpg]
\starttext
\dorecurse {10} {
\expanded{\externalfigure[\ChooseGraphic][width=4cm]}
}
\stoptext
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________