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 getRegImgHeight(position, resolution, targetwidth) -- position (top/bottom), target resolution [dpi], target width [sp] local pic = img.scan{filename = figures.current().status.fullname} --local pic = figures.getinfo(figures.current().status.fullname) local picH = pic.ysize * TEXptpi * TEXpt / resolution -- picture height in sp local picW = pic.xsize * TEXptpi * TEXpt / resolution -- picture width in sp local bleed = tex.getdimen("Bleed") local lineH = tex.getdimen("lineheight") local scaling = targetwidth / picW -- scaling factor picH = picH * scaling -- scaled image height local nettoPicHeight = picH if position == "bottom" then local bottomOffset = bleed + tex.getdimen("bottomheight") + tex.getdimen("bottomdistance") + tex.getdimen("footerheight") + tex.getdimen("footerdistance") nettoPicHeight = picH - bottomOffset -- image height minus everything below the last line else -- position "top" or whatever local topOffset = bleed + tex.getdimen("topspace") + tex.getdimen("headerheight") + tex.getdimen("headerdistance") + tex.getdimen("topdistance") local topskip = glue2num(tex.topskip) nettoPicHeight = picH - topOffset - topskip -- image height minus everything above the first line end local cutY = math.floor(nettoPicHeight) % math.floor(lineH) -- space to cut away (what exceeds the line grid) context((picH - cutY) .. "sp") -- final image height end