* image file resolver in Lua? @ 2018-02-02 7:40 Henning Hraban Ramm 2018-02-02 11:08 ` Rudolf Bahr 0 siblings, 1 reply; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-02 7:40 UTC (permalink / raw) To: mailing list for ConTeXt users Ahoi, I’m using a Lua function to calculate image sizes, cropping etc. This snippet: local filename = figures.current().status.fullname local pic = img.scan{filename = filename} ... works most of the time, but sometimes the "current" image is the previous one, might be because I’m using layers and postponing. So I’d like to use just the same filename as I give to \externalfigure, i.e. without path and extension. How can I address the same file path resolver in my Lua function? Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-02 7:40 image file resolver in Lua? Henning Hraban Ramm @ 2018-02-02 11:08 ` Rudolf Bahr 2018-02-02 15:17 ` Henning Hraban Ramm 0 siblings, 1 reply; 14+ messages in thread From: Rudolf Bahr @ 2018-02-02 11:08 UTC (permalink / raw) To: mailing list for ConTeXt users On Fri, Feb 02, 2018 at 08:40:08AM +0100, Henning Hraban Ramm wrote: > Ahoi, > > I’m using a Lua function to calculate image sizes, cropping etc. > This snippet: > > local filename = figures.current().status.fullname > local pic = img.scan{filename = filename} > > ... works most of the time, but sometimes the "current" image is the previous one, might be because I’m using layers and postponing. > So I’d like to use just the same filename as I give to \externalfigure, i.e. without path and extension. > How can I address the same file path resolver in my Lua function? > Moin, Hraban, where could I find something about those lua functions? Regards, Rudolf ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-02 11:08 ` Rudolf Bahr @ 2018-02-02 15:17 ` Henning Hraban Ramm 2018-02-03 6:57 ` Rudolf Bahr 0 siblings, 1 reply; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-02 15:17 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1: Type: text/plain, Size: 2832 bytes --] Am 2018-02-02 um 12:08 schrieb Rudolf Bahr <quasi@quasi.de>: > On Fri, Feb 02, 2018 at 08:40:08AM +0100, Henning Hraban Ramm wrote: >> Ahoi, >> >> I’m using a Lua function to calculate image sizes, cropping etc. >> This snippet: >> >> local filename = figures.current().status.fullname >> local pic = img.scan{filename = filename} >> >> ... works most of the time, but sometimes the "current" image is the previous one, might be because I’m using layers and postponing. >> So I’d like to use just the same filename as I give to \externalfigure, i.e. without path and extension. >> How can I address the same file path resolver in my Lua function? >> > > Moin, Hraban, > > where could I find something about those lua functions? Maybe here: http://source.contextgarden.net/tex/context/base/mkiv/grph-inc.lua The image placement functions I’m using are something Hans and others helped me accomplish during the last meeting; AFAIK there’s no real documentation. Find attached the lua part. It’s probably more complicated than necessary I could work around my original problem: I’m using my image with \externalfigure in an invisible place first, so it’s current, and figures.current().status is the right one. :) Here’s my (convoluted) placement macro: % image on empty page, caption in margin % usage: % \startpostponing[pagenumber] % \pagefig[reference]{caption}{filename} % \stoppostponing % postponing is important, otherwise the page numbering gets wrong \def\pagefig{\dosingleempty\doPagefig} \def\doPagefig[#1]#2#3{ % calculate image size \startfullpagemakeup \externalfigure[#3][width=1mm] % dummy to set image as current \def\myClipHeight{\ctxlua{ctxClipHeight("#3", \Resolution)}} \def\mystartY{\ctxlua{ctxStartY("#3", \Resolution)}} % image \setlayerframed[bglayer][% frame=off, offset=overlay, x=21mm, y=\mystartY, height=\myClipHeight, width=\textwidth, align=flushleft, ]{% \clip[ width=\textwidth, height=\myClipHeight, hoffset=0mm, voffset=0mm, % i.e. clip bottom! TODO: options! ]{\externalfigure[#3][width=\textwidth]} } \textreference[pre#1]{\myImgHeight} % caption \setlayerframed[bglayer][% frame=off, offset=overlay, linecorrection=on, x=143mm,y=\dimexpr\mystartY + 3pt\relax, height=\myClipHeight, width=\outermarginwidth, align={flushleft,low}, valign=bottom, ]{% \vbox{ \textreference[#1]{\strut #2}\vfill #2 }} \stopfullpagemakeup } usage example: \startpostponing[82] \pagefig[alinari-stelzen]{Gebrüder Alinari (Florenz, 19. Jhd.)}{ka34/img/Gebr-Alinari_Kinder_auf_Stelzen} \stoppostponing Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD [-- Attachment #2: grph-imagesize.lua --] [-- Type: application/octet-stream, Size: 2592 bytes --] TEXpt = 65536 -- sp per pt TEXptpi = 72.27 -- pt per inch function sp2mm(n) -- convert sp into mm return math.floor(n * 35.28 / TEXpt)/100 end function glue2num(glue) -- convert TeX glue (e.g. skips) into dimensions(? or numbers) return glue.width + (glue.stretch * glue.stretch_order) - (glue.shrink * glue.shrink_order) end function getImgHeight(filename, resolution) -- filename, target resolution [dpi] -- filename is not used ATM, just current image print("LUA getRegImgHeight(" .. filename .. ", " .. resolution .. ")") local targetwidth = tex.getdimen("textwidth") filename = figures.current().status.fullname local pic = img.scan{filename = filename} local picH = pic.ysize * TEXptpi * TEXpt / resolution -- picture height in sp local picW = pic.xsize * TEXptpi * TEXpt / resolution -- picture width in sp print("LUA picH: " .. picH .. " / ysize: " .. pic.ysize) local scaling = targetwidth / picW -- scaling factor picH = picH * scaling -- scaled image height return picH end function ctxImgHeight(filename, resolution) context(getImgHeight(filename, resolution) .. "sp") end function getClipHeight(picH) -- image should sit on a grid line and occupy n whole lines plus -- 2/3 of a line to "start" with middle length of type local lineH = tex.getdimen("lineheight") local picLY = math.floor(picH / lineH) -- image height in whole lines local clipY = lineH * picLY -- clipped image height local picTop = picH % lineH -- rest of image height local firstSkip = 2/3 * lineH -- first line if picTop >= firstSkip then clipY = clipY + firstSkip -- add first line else clipY = clipY - (1/2 * lineH) -- clip to first line end --context(clipY .. "sp") return clipY end function ctxClipHeight(filename, resolution) context(getClipHeight(getImgHeight(filename, resolution)) .. "sp") end function getStartY(picH) -- I need an absolute y coordinate for image placement local Ycorr = 2 * TEXpt -- y correction local topOffset = tex.getdimen("topspace") + tex.getdimen("headerheight") + tex.getdimen("headerdistance") + tex.getdimen("topdistance") local topskip = glue2num(tex.topskip) local textH = tex.getdimen("textheight") local lineH = tex.getdimen("lineheight") local skipH = (textH - picH) / 3 -- spread space 2:3 local skipL = math.floor(skipH / lineH) skipH = skipL * lineH + 1/3 * lineH -- within type area skipH = skipH + topOffset + topskip + Ycorr return skipH end function ctxStartY(filename, resolution) context(getStartY(getClipHeight(getImgHeight(filename, resolution))) .. "sp") end [-- Attachment #3: Type: text/plain, Size: 492 bytes --] ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-02 15:17 ` Henning Hraban Ramm @ 2018-02-03 6:57 ` Rudolf Bahr 2018-02-04 12:06 ` Hans Hagen 0 siblings, 1 reply; 14+ messages in thread From: Rudolf Bahr @ 2018-02-03 6:57 UTC (permalink / raw) To: mailing list for ConTeXt users On Fri, Feb 02, 2018 at 04:17:32PM +0100, Henning Hraban Ramm wrote: > Am 2018-02-02 um 12:08 schrieb Rudolf Bahr <quasi@quasi.de>: > > > On Fri, Feb 02, 2018 at 08:40:08AM +0100, Henning Hraban Ramm wrote: > >> Ahoi, > >> > >> I’m using a Lua function to calculate image sizes, cropping etc. > >> This snippet: > >> > >> local filename = figures.current().status.fullname > >> local pic = img.scan{filename = filename} > >> > >> ... works most of the time, but sometimes the "current" image is the previous one, might be because I’m using layers and postponing. > >> So I’d like to use just the same filename as I give to \externalfigure, i.e. without path and extension. > >> How can I address the same file path resolver in my Lua function? > >> > > > > Moin, Hraban, > > > > where could I find something about those lua functions? > > Maybe here: http://source.contextgarden.net/tex/context/base/mkiv/grph-inc.lua > > The image placement functions I’m using are something Hans and others helped me accomplish during the last meeting; AFAIK there’s no real documentation. > > Find attached the lua part. It’s probably more complicated than necessary > > > I could work around my original problem: I’m using my image with \externalfigure in an invisible place first, so it’s current, and figures.current().status is the right one. :) > > Here’s my (convoluted) placement macro: > > % image on empty page, caption in margin > % usage: > % \startpostponing[pagenumber] > % \pagefig[reference]{caption}{filename} > % \stoppostponing > % postponing is important, otherwise the page numbering gets wrong > \def\pagefig{\dosingleempty\doPagefig} > \def\doPagefig[#1]#2#3{ > % calculate image size > \startfullpagemakeup > \externalfigure[#3][width=1mm] % dummy to set image as current > \def\myClipHeight{\ctxlua{ctxClipHeight("#3", \Resolution)}} > \def\mystartY{\ctxlua{ctxStartY("#3", \Resolution)}} > % image > \setlayerframed[bglayer][% > frame=off, > offset=overlay, > x=21mm, > y=\mystartY, > height=\myClipHeight, > width=\textwidth, > align=flushleft, > ]{% > \clip[ > width=\textwidth, > height=\myClipHeight, > hoffset=0mm, > voffset=0mm, % i.e. clip bottom! TODO: options! > ]{\externalfigure[#3][width=\textwidth]} > } > \textreference[pre#1]{\myImgHeight} > % caption > \setlayerframed[bglayer][% > frame=off, > offset=overlay, > linecorrection=on, > x=143mm,y=\dimexpr\mystartY + 3pt\relax, > height=\myClipHeight, > width=\outermarginwidth, > align={flushleft,low}, > valign=bottom, > ]{% > \vbox{ > \textreference[#1]{\strut #2}\vfill #2 > }} > \stopfullpagemakeup > } > > > usage example: > > \startpostponing[82] > \pagefig[alinari-stelzen]{Gebrüder Alinari (Florenz, 19. Jhd.)}{ka34/img/Gebr-Alinari_Kinder_auf_Stelzen} > \stoppostponing > > > > Greetlings, Hraban > --- > http://www.fiee.net > http://wiki.contextgarden.net > GPG Key ID 1C9B22FD > Moin Hraban! It's very interesting for me to see, how exactly you calculate the size of images and texts with the help of lua! Up to now I used to use python and a independend lua to provide some necessary data for context. For instance python invokes graphicsmagick in order to get the size of images. Because it's provided in px and not in pt, so often some further manual work is unavoidable. Now, since lua and metafun are well integrated into context it suggests itself to use luatex instead of python, though I like this language very much. Thank you very much, Hraban, for putting your macros and links at my disposal! Regards, Rudolf ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-03 6:57 ` Rudolf Bahr @ 2018-02-04 12:06 ` Hans Hagen 2018-02-04 18:04 ` Henning Hraban Ramm ` (3 more replies) 0 siblings, 4 replies; 14+ messages in thread From: Hans Hagen @ 2018-02-04 12:06 UTC (permalink / raw) To: ntg-context On 2/3/2018 7:57 AM, Rudolf Bahr wrote: > On Fri, Feb 02, 2018 at 04:17:32PM +0100, Henning Hraban Ramm wrote: >> Am 2018-02-02 um 12:08 schrieb Rudolf Bahr <quasi@quasi.de>: >> >>> On Fri, Feb 02, 2018 at 08:40:08AM +0100, Henning Hraban Ramm wrote: >>>> Ahoi, >>>> >>>> I’m using a Lua function to calculate image sizes, cropping etc. >>>> This snippet: >>>> >>>> local filename = figures.current().status.fullname >>>> local pic = img.scan{filename = filename} >>>> >>>> ... works most of the time, but sometimes the "current" image is the previous one, might be because I’m using layers and postponing. >>>> So I’d like to use just the same filename as I give to \externalfigure, i.e. without path and extension. >>>> How can I address the same file path resolver in my Lua function? >>>> >>> >>> Moin, Hraban, >>> >>> where could I find something about those lua functions? >> >> Maybe here: http://source.contextgarden.net/tex/context/base/mkiv/grph-inc.lua >> >> The image placement functions I’m using are something Hans and others helped me accomplish during the last meeting; AFAIK there’s no real documentation. >> >> Find attached the lua part. It’s probably more complicated than necessary >> >> >> I could work around my original problem: I’m using my image with \externalfigure in an invisible place first, so it’s current, and figures.current().status is the right one. :) >> >> Here’s my (convoluted) placement macro: >> >> % image on empty page, caption in margin >> % usage: >> % \startpostponing[pagenumber] >> % \pagefig[reference]{caption}{filename} >> % \stoppostponing >> % postponing is important, otherwise the page numbering gets wrong >> \def\pagefig{\dosingleempty\doPagefig} >> \def\doPagefig[#1]#2#3{ >> % calculate image size >> \startfullpagemakeup >> \externalfigure[#3][width=1mm] % dummy to set image as current >> \def\myClipHeight{\ctxlua{ctxClipHeight("#3", \Resolution)}} >> \def\mystartY{\ctxlua{ctxStartY("#3", \Resolution)}} >> % image >> \setlayerframed[bglayer][% >> frame=off, >> offset=overlay, >> x=21mm, >> y=\mystartY, >> height=\myClipHeight, >> width=\textwidth, >> align=flushleft, >> ]{% >> \clip[ >> width=\textwidth, >> height=\myClipHeight, >> hoffset=0mm, >> voffset=0mm, % i.e. clip bottom! TODO: options! >> ]{\externalfigure[#3][width=\textwidth]} >> } >> \textreference[pre#1]{\myImgHeight} >> % caption >> \setlayerframed[bglayer][% >> frame=off, >> offset=overlay, >> linecorrection=on, >> x=143mm,y=\dimexpr\mystartY + 3pt\relax, >> height=\myClipHeight, >> width=\outermarginwidth, >> align={flushleft,low}, >> valign=bottom, >> ]{% >> \vbox{ >> \textreference[#1]{\strut #2}\vfill #2 >> }} >> \stopfullpagemakeup >> } >> >> >> usage example: >> >> \startpostponing[82] >> \pagefig[alinari-stelzen]{Gebrüder Alinari (Florenz, 19. Jhd.)}{ka34/img/Gebr-Alinari_Kinder_auf_Stelzen} >> \stoppostponing >> >> >> >> Greetlings, Hraban >> --- >> http://www.fiee.net >> http://wiki.contextgarden.net >> GPG Key ID 1C9B22FD >> > > Moin Hraban! > > It's very interesting for me to see, how exactly you calculate > the size of images and texts with the help of lua! > > Up to now I used to use python and a independend lua to provide some > necessary data for context. For instance python invokes graphicsmagick > in order to get the size of images. Because it's provided in px and not > in pt, so often some further manual work is unavoidable. > > Now, since lua and metafun are well integrated into context it suggests > itself to use luatex instead of python, though I like this language > very much. > > Thank you very much, Hraban, for putting your macros and links > at my disposal! Not sure what you want top know but a lot of image properties can be checked by prerolling: \starttext \getfiguredimensions[t:/sources/cow.pdf] \starttabulate[|T|T|] \NC \string\figurewidth \NC \figurewidth \NC \NR \NC \string\figureheight \NC \figureheight \NC \NR \NC \string\figurexscale \NC \figurexscale \NC \NR \NC \string\figureyscale \NC \figureyscale \NC \NR \TB \NC \string\figuresize \NC \figuresize \NC \NR \NC \string\figurelabel \NC \figurelabel \NC \NR \NC \string\figurefileoriginal \NC \figurefileoriginal \NC \NR \NC \string\figurefilepage \NC \figurefilepage \NC \NR \NC \string\figurefileoptions \NC \figurefileoptions \NC \NR \NC \string\figurefileconversion\NC \figurefileconversion\NC \NR \NC \string\figurefileresolution\NC \figurefileresolution\NC \NR \NC \string\figurefilecolor \NC \figurefilecolor \NC \NR \NC \string\figurefilearguments \NC \figurefilearguments \NC \NR \NC \string\figurefilecache \NC \figurefilecache \NC \NR \NC \string\figurefileprefix \NC \figurefileprefix \NC \NR \TB \NC \string\figurenaturalwidth \NC \figurenaturalwidth \NC \NR \NC \string\figurenaturalheight \NC \figurenaturalheight \NC \NR \NC \string\figurexresolution \NC \figurexresolution \NC \NR \NC \string\figureyresolution \NC \figureyresolution \NC \NR \NC \string\figureorientation \NC \figureorientation \NC \NR \NC \string\figurerotation \NC \figurerotation \NC \NR \NC \string\figurexsize \NC \figurexsize \NC \NR \NC \string\figureysize \NC \figureysize \NC \NR \NC \string\figurecolordepth \NC \figurecolordepth \NC \NR \NC \string\figuredepth \NC \figuredepth \NC \NR \TB \NC \string\figurefullname \NC \figurefullname \NC \NR \NC \string\noffigurepages \NC \noffigurepages \NC \NR \TB \NC \string\figurefilepath \NC \figurefilepath \NC \NR \NC \string\figurefilename \NC \figurefilename \NC \NR \NC \string\figurefiletype \NC \figurefiletype \NC \NR \stoptabulate \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-04 12:06 ` Hans Hagen @ 2018-02-04 18:04 ` Henning Hraban Ramm 2018-02-05 20:22 ` Pablo Rodriguez 2018-02-06 8:34 ` Procházka Lukáš Ing. 2018-02-05 14:12 ` Rudolf Bahr ` (2 subsequent siblings) 3 siblings, 2 replies; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-04 18:04 UTC (permalink / raw) To: mailing list for ConTeXt users Am 2018-02-04 um 13:06 schrieb Hans Hagen <pragma@wxs.nl>: > Not sure what you want top know but a lot of image properties can be checked by prerolling: > \getfiguredimensions[t:/sources/cow.pdf] This is really interesting, but my original question was about the file path resolver, i.e. how to get "t:/sources/cow.pdf" from just "cow"? Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-04 18:04 ` Henning Hraban Ramm @ 2018-02-05 20:22 ` Pablo Rodriguez 2018-02-06 8:34 ` Procházka Lukáš Ing. 1 sibling, 0 replies; 14+ messages in thread From: Pablo Rodriguez @ 2018-02-05 20:22 UTC (permalink / raw) To: ntg-context On 02/04/2018 07:04 PM, Henning Hraban Ramm wrote: > Am 2018-02-04 um 13:06 schrieb Hans Hagen <pragma@wxs.nl>: > >> Not sure what you want top know but a lot of image properties can be checked by prerolling: >> \getfiguredimensions[t:/sources/cow.pdf] > > This is really interesting, but my original question was about the > file path resolver, i.e. how to get "t:/sources/cow.pdf" from just "cow"? Hi Hraban, in case your question remains unanswered (which isn’t clear to me): \setupexternalfigures[location=default] \starttext \getfiguredimensions[cow.pdf] \starttabulate[|T|T|] \NC \string\figurefullname \NC \figurefullname \NC \NR \NC \string\figurefilepath \NC \figurefilepath \NC \NR \NC \string\figurefilename \NC \figurefilename \NC \NR \NC \string\figurefiletype \NC \figurefiletype \NC \NR \stoptabulate \stoptext Just in case it helps, Pablo -- http://www.ousia.tk ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-04 18:04 ` Henning Hraban Ramm 2018-02-05 20:22 ` Pablo Rodriguez @ 2018-02-06 8:34 ` Procházka Lukáš Ing. 2018-02-06 12:13 ` Henning Hraban Ramm 1 sibling, 1 reply; 14+ messages in thread From: Procházka Lukáš Ing. @ 2018-02-06 8:34 UTC (permalink / raw) To: mailing list for ConTeXt users Hello Henning, > This is really interesting, but my original question was about the file path resolver, i.e. how to get "t:/sources/cow.pdf" from just "cow"? > I guess there was a similar question here: https://mailman.ntg.nl/pipermail/ntg-context/2017/088324.html Reading till the end, I deduce one has to collect snippets which appear in the code to build its own "file locator" as no function like "MyExternalFigureLocator()" exists in ConTeXt/Lua API. Some highlights: ---- > Personally I use the lua variable named : figures.path > > It’s a lua table which contains directories names you provide in directory= in \setupexternalfigures: > > for _, path in ipairs(figures.paths) do > local figure_file = path .. '/' .. file > local doc = lpdf.epdf.load(figure_file) -- assume pdf (just an example) > if doc then > …. > end > done ---- Unfortunately, this code supposes the figure name was passed WITH extension, as no lookup in table-of-valid-extensions is performed (maybe no such table nor iterator exists). There should be also: ---- local n = "x:/Users/MMi/Akce/I-6_Krusovice.DSP-ZDS/Admin/Jednani/2017-07-07-SU-Rakovnik/ZJ.pdf" local d = figures.getinfo(n) inspect(d) ---- And a snippet from another mailing thread: ---- (Hans' answer) \getfiguredimensions[test.pdf] \dorecurse {\noffigurepages} { \getfiguredimensions[test.pdf][page=#1] \figurenaturalwidth ,\figurenaturalheight,\figureorientation,\figurerotation\par } in lua you can either use the img library (see luatex manual) or context helpers local data = figures.push("foo.pdf") figures.identify() figures.check() figures.pop() inspect(data) i'll add: function figures.getinfo(name,page) if type(name) == "string" then name = { name = name, page = page } end if name.name then local data = figures.push(name) figures.identify() figures.check() figures.pop() return data end end so that one can do local n = "ms.pdf" local d = figures.getinfo(n) if d then for i=1,d.used.pages do local p = figures.getinfo(n,i) if p then local u = p.used print(u.width,u.height,u.orientation) end end end ---- Hope this helps. Best regards, Lukas On Sun, 04 Feb 2018 19:04:28 +0100, Henning Hraban Ramm <texml@fiee.net> wrote: > > Greetlings, Hraban > --- > http://www.fiee.net > http://wiki.contextgarden.net > GPG Key ID 1C9B22FD > > ___________________________________________________________________________________ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___________________________________________________________________________________ -- Ing. Lukáš Procházka | mailto:LPr@pontex.cz Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS:nrpt3sn Bezová 1658 147 14 Praha 4 Mob.: +420 702 033 396 ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-06 8:34 ` Procházka Lukáš Ing. @ 2018-02-06 12:13 ` Henning Hraban Ramm 2018-02-06 16:09 ` Procházka Lukáš Ing. 0 siblings, 1 reply; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-06 12:13 UTC (permalink / raw) To: mailing list for ConTeXt users Am 2018-02-06 um 09:34 schrieb Procházka Lukáš Ing. <LPr@pontex.cz>: > Hello Henning, > >> This is really interesting, but my original question was about the file path resolver, i.e. how to get "t:/sources/cow.pdf" from just "cow"? >> > > I guess there was a similar question here: > > https://mailman.ntg.nl/pipermail/ntg-context/2017/088324.html > > Reading till the end, I deduce one has to collect snippets which appear in the code to build its own "file locator" as no function like "MyExternalFigureLocator()" exists in ConTeXt/Lua API. Dear Lukáš, thank you very much for collecting this information! I’ll try as soon as I get some time, since algorithmic image placement is a recurring problem for me, as I try to replace InDesign in my workflow. I thought about providing a module, but each of my projects has so differing needs that either every macro would need a bunch of options, or I need a lot of similar macros. We’ll see... Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-06 12:13 ` Henning Hraban Ramm @ 2018-02-06 16:09 ` Procházka Lukáš Ing. 2018-02-06 19:51 ` Henning Hraban Ramm 0 siblings, 1 reply; 14+ messages in thread From: Procházka Lukáš Ing. @ 2018-02-06 16:09 UTC (permalink / raw) To: mailing list for ConTeXt users Hello Henning, On Tue, 06 Feb 2018 13:13:12 +0100, Henning Hraban Ramm <texml@fiee.net> wrote: > I’ll try as soon as I get some time, since algorithmic image placement is a recurring problem for me, as I try to replace InDesign in my workflow. > > I thought about providing a module, but each of my projects has so differing needs that either every macro would need a bunch of options, or I need a lot of similar macros. We’ll see... > my experience in these situations: I'm usually implementing complicated solutions via Lua, with functions with obligatory arg(s) first followed by one optional argument of table type: - it's easy to investigate this optional argument and alter the algorithm depending on table keys (presence and/or value), - you don't have to be afraid of optional arg(s) rearrangement. To be more concrete: ---- Sample Lua code MyPlaceFigure = function(figname, opts) -- Optional; .scale = .sc, .rotation = .rot, .label, ... opts = opts or {} -- To simplify code bellow local scale, rot, lab = opts.scale or opts.sc, -- I.e. more keys are allowed in long/short alternative opts.rotation or opts.rotate or opts.rot, -- dtto opts.label or opts.lab, nil if label then -- E.g. use context.placefloat(...) else context.externalfigure({figname}, {scale = 1000 * scale, orientation = rot, }) end end ---- Best regards, Lukas > Greetlings, Hraban -- Ing. Lukáš Procházka | mailto:LPr@pontex.cz Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS:nrpt3sn Bezová 1658 147 14 Praha 4 Mob.: +420 702 033 396 ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-06 16:09 ` Procházka Lukáš Ing. @ 2018-02-06 19:51 ` Henning Hraban Ramm 0 siblings, 0 replies; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-06 19:51 UTC (permalink / raw) To: mailing list for ConTeXt users Am 2018-02-06 um 17:09 schrieb Procházka Lukáš Ing. <LPr@pontex.cz>: > I'm usually implementing complicated solutions via Lua, with functions with obligatory arg(s) first followed by one optional argument of table type: Thank you for your effort! I actually already wrote parts of my invoicing solution in Lua. I was planning to even run a simple GUI (tekui) on top of LuaTeX, but my priorities keep shifting... At the moment I got shell scripts that call Python scripts that read JSON files (as a simple database) and write ConTeXt code that includes (object oriented) Lua libraries for most of the the calculations... It works well enough for my own company and our publishing house, but is quite convoluted. Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-04 12:06 ` Hans Hagen 2018-02-04 18:04 ` Henning Hraban Ramm @ 2018-02-05 14:12 ` Rudolf Bahr 2018-02-08 20:40 ` Henning Hraban Ramm 2018-02-20 9:03 ` Henning Hraban Ramm 3 siblings, 0 replies; 14+ messages in thread From: Rudolf Bahr @ 2018-02-05 14:12 UTC (permalink / raw) To: mailing list for ConTeXt users On Sun, Feb 04, 2018 at 01:06:08PM +0100, Hans Hagen wrote: > On 2/3/2018 7:57 AM, Rudolf Bahr wrote: > > On Fri, Feb 02, 2018 at 04:17:32PM +0100, Henning Hraban Ramm wrote: > > > Am 2018-02-02 um 12:08 schrieb Rudolf Bahr <quasi@quasi.de>: > > > > > > > On Fri, Feb 02, 2018 at 08:40:08AM +0100, Henning Hraban Ramm wrote: > > > > > Ahoi, > > > > > > > > > > I’m using a Lua function to calculate image sizes, cropping etc. > > > > > This snippet: > > > > > > > > > > local filename = figures.current().status.fullname > > > > > local pic = img.scan{filename = filename} > > > > > > > > > > ... works most of the time, but sometimes the "current" image is the previous one, might be because I’m using layers and postponing. > > > > > So I’d like to use just the same filename as I give to \externalfigure, i.e. without path and extension. > > > > > How can I address the same file path resolver in my Lua function? > > > > > > > > > > > > > Moin, Hraban, > > > > > > > > where could I find something about those lua functions? > > > > > > Maybe here: http://source.contextgarden.net/tex/context/base/mkiv/grph-inc.lua > > > > > > The image placement functions I’m using are something Hans and others helped me accomplish during the last meeting; AFAIK there’s no real documentation. > > > > > > Find attached the lua part. It’s probably more complicated than necessary > > > > > > > > > I could work around my original problem: I’m using my image with \externalfigure in an invisible place first, so it’s current, and figures.current().status is the right one. :) > > > > > > Here’s my (convoluted) placement macro: > > > > > > % image on empty page, caption in margin > > > % usage: > > > % \startpostponing[pagenumber] > > > % \pagefig[reference]{caption}{filename} > > > % \stoppostponing > > > % postponing is important, otherwise the page numbering gets wrong > > > \def\pagefig{\dosingleempty\doPagefig} > > > \def\doPagefig[#1]#2#3{ > > > % calculate image size > > > \startfullpagemakeup > > > \externalfigure[#3][width=1mm] % dummy to set image as current > > > \def\myClipHeight{\ctxlua{ctxClipHeight("#3", \Resolution)}} > > > \def\mystartY{\ctxlua{ctxStartY("#3", \Resolution)}} > > > % image > > > \setlayerframed[bglayer][% > > > frame=off, > > > offset=overlay, > > > x=21mm, > > > y=\mystartY, > > > height=\myClipHeight, > > > width=\textwidth, > > > align=flushleft, > > > ]{% > > > \clip[ > > > width=\textwidth, > > > height=\myClipHeight, > > > hoffset=0mm, > > > voffset=0mm, % i.e. clip bottom! TODO: options! > > > ]{\externalfigure[#3][width=\textwidth]} > > > } > > > \textreference[pre#1]{\myImgHeight} > > > % caption > > > \setlayerframed[bglayer][% > > > frame=off, > > > offset=overlay, > > > linecorrection=on, > > > x=143mm,y=\dimexpr\mystartY + 3pt\relax, > > > height=\myClipHeight, > > > width=\outermarginwidth, > > > align={flushleft,low}, > > > valign=bottom, > > > ]{% > > > \vbox{ > > > \textreference[#1]{\strut #2}\vfill #2 > > > }} > > > \stopfullpagemakeup > > > } > > > > > > > > > usage example: > > > > > > \startpostponing[82] > > > \pagefig[alinari-stelzen]{Gebrüder Alinari (Florenz, 19. Jhd.)}{ka34/img/Gebr-Alinari_Kinder_auf_Stelzen} > > > \stoppostponing > > > > > > > > > > > > Greetlings, Hraban > > > --- > > > http://www.fiee.net > > > http://wiki.contextgarden.net > > > GPG Key ID 1C9B22FD > > > > > > > Moin Hraban! > > > > It's very interesting for me to see, how exactly you calculate > > the size of images and texts with the help of lua! > > > > Up to now I used to use python and a independend lua to provide some > > necessary data for context. For instance python invokes graphicsmagick > > in order to get the size of images. Because it's provided in px and not > > in pt, so often some further manual work is unavoidable. > > > > Now, since lua and metafun are well integrated into context it suggests > > itself to use luatex instead of python, though I like this language > > very much. > > > > Thank you very much, Hraban, for putting your macros and links > > at my disposal! > Not sure what you want top know but a lot of image properties can be checked > by prerolling: > > \starttext > > \getfiguredimensions[t:/sources/cow.pdf] > > \starttabulate[|T|T|] > \NC \string\figurewidth \NC \figurewidth \NC \NR > \NC \string\figureheight \NC \figureheight \NC \NR > \NC \string\figurexscale \NC \figurexscale \NC \NR > \NC \string\figureyscale \NC \figureyscale \NC \NR > \TB > \NC \string\figuresize \NC \figuresize \NC \NR > \NC \string\figurelabel \NC \figurelabel \NC \NR > \NC \string\figurefileoriginal \NC \figurefileoriginal \NC \NR > \NC \string\figurefilepage \NC \figurefilepage \NC \NR > \NC \string\figurefileoptions \NC \figurefileoptions \NC \NR > \NC \string\figurefileconversion\NC \figurefileconversion\NC \NR > \NC \string\figurefileresolution\NC \figurefileresolution\NC \NR > \NC \string\figurefilecolor \NC \figurefilecolor \NC \NR > \NC \string\figurefilearguments \NC \figurefilearguments \NC \NR > \NC \string\figurefilecache \NC \figurefilecache \NC \NR > \NC \string\figurefileprefix \NC \figurefileprefix \NC \NR > \TB > \NC \string\figurenaturalwidth \NC \figurenaturalwidth \NC \NR > \NC \string\figurenaturalheight \NC \figurenaturalheight \NC \NR > \NC \string\figurexresolution \NC \figurexresolution \NC \NR > \NC \string\figureyresolution \NC \figureyresolution \NC \NR > \NC \string\figureorientation \NC \figureorientation \NC \NR > \NC \string\figurerotation \NC \figurerotation \NC \NR > \NC \string\figurexsize \NC \figurexsize \NC \NR > \NC \string\figureysize \NC \figureysize \NC \NR > \NC \string\figurecolordepth \NC \figurecolordepth \NC \NR > \NC \string\figuredepth \NC \figuredepth \NC \NR > \TB > \NC \string\figurefullname \NC \figurefullname \NC \NR > \NC \string\noffigurepages \NC \noffigurepages \NC \NR > \TB > \NC \string\figurefilepath \NC \figurefilepath \NC \NR > \NC \string\figurefilename \NC \figurefilename \NC \NR > \NC \string\figurefiletype \NC \figurefiletype \NC \NR > \stoptabulate > > \stoptext > > This is very good and useful, thank you, Hans! I need this to set a bunch of family history books with plenty of photos, texts, family trees, journey diaries, scans, index of persons etc. With the help of context+luatex+metafun I'd like to set the pages hopefully without the need of too much manual corrections, i.e in a as far as possible automated way. There is a lot of material, especially nowadays the flood of digital pictures. At the moment I succeed in setting only 2 or 3 such year-books per year. Thanks again for your help, Rudolf ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-04 12:06 ` Hans Hagen 2018-02-04 18:04 ` Henning Hraban Ramm 2018-02-05 14:12 ` Rudolf Bahr @ 2018-02-08 20:40 ` Henning Hraban Ramm 2018-02-20 9:03 ` Henning Hraban Ramm 3 siblings, 0 replies; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-08 20:40 UTC (permalink / raw) To: mailing list for ConTeXt users Am 2018-02-04 um 13:06 schrieb Hans Hagen <pragma@wxs.nl>: > Not sure what you want top know but a lot of image properties can be checked by prerolling: > > \getfiguredimensions[t:/sources/cow.pdf] ... > \NC \string\figurefilepath \NC \figurefilepath \NC \NR > \NC \string\figurefilename \NC \figurefilename \NC \NR > \NC \string\figurefiletype \NC \figurefiletype \NC \NR Sorry, I didn’t recognize that this also answered my question! Seems like I can condense my calculations a lot... I started some documentation here: http://wiki.contextgarden.net/Image_Placement A few of the variables don’t work: \figurefileresolution, \figurefilecolor, \figurefilearguments, \figureorientation and \figurerotation all lead to errors. I checked only in the garden yet, so maybe these are quite new? Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: image file resolver in Lua? 2018-02-04 12:06 ` Hans Hagen ` (2 preceding siblings ...) 2018-02-08 20:40 ` Henning Hraban Ramm @ 2018-02-20 9:03 ` Henning Hraban Ramm 3 siblings, 0 replies; 14+ messages in thread From: Henning Hraban Ramm @ 2018-02-20 9:03 UTC (permalink / raw) To: mailing list for ConTeXt users Am 2018-02-04 um 13:06 schrieb Hans Hagen <pragma@wxs.nl>: > \getfiguredimensions[t:/sources/cow.pdf] > > \starttabulate[|T|T|] > \NC \string\figurewidth \NC \figurewidth \NC \NR > \NC \string\figureheight \NC \figureheight \NC \NR > \NC \string\figurexscale \NC \figurexscale \NC \NR > \NC \string\figureyscale \NC \figureyscale \NC \NR ... > \TB > \NC \string\figurefullname \NC \figurefullname \NC \NR > \NC \string\noffigurepages \NC \noffigurepages \NC \NR > \TB > \NC \string\figurefilepath \NC \figurefilepath \NC \NR > \NC \string\figurefilename \NC \figurefilename \NC \NR > \NC \string\figurefiletype \NC \figurefiletype \NC \NR > \stoptabulate Next try: How can I access these values from Lua? While \ctxlua{print("\figureheight")} works, context.figureheight is a function value (?), context.figureheight() or tex.figureheight() is nil, tex.getdimen("figureheight") is also wrong, and it’s also no glue. I’d be thankful for a hint. Greetlings, Hraban --- http://www.fiee.net http://wiki.contextgarden.net GPG Key ID 1C9B22FD ___________________________________________________________________________________ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2018-02-20 9:03 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-02-02 7:40 image file resolver in Lua? Henning Hraban Ramm 2018-02-02 11:08 ` Rudolf Bahr 2018-02-02 15:17 ` Henning Hraban Ramm 2018-02-03 6:57 ` Rudolf Bahr 2018-02-04 12:06 ` Hans Hagen 2018-02-04 18:04 ` Henning Hraban Ramm 2018-02-05 20:22 ` Pablo Rodriguez 2018-02-06 8:34 ` Procházka Lukáš Ing. 2018-02-06 12:13 ` Henning Hraban Ramm 2018-02-06 16:09 ` Procházka Lukáš Ing. 2018-02-06 19:51 ` Henning Hraban Ramm 2018-02-05 14:12 ` Rudolf Bahr 2018-02-08 20:40 ` Henning Hraban Ramm 2018-02-20 9:03 ` Henning Hraban Ramm
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).