ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Henning Hraban Ramm <texml@fiee.net>
To: ntg-context@ntg.nl
Subject: Re: lmtx: img?
Date: Sat, 03 Aug 2019 07:02:29 +0000	[thread overview]
Message-ID: <20190803070229.Horde.hJ_Kt2F9cdfKVMhaPbbaELt@webmail.fiee.net> (raw)
In-Reply-To: <3e3b91a4-c479-92a3-ff79-6cfef20667ee@xs4all.nl>

[-- Attachment #1: Type: text/plain, Size: 869 bytes --]

Zitat von Hans Hagen <j.hagen@xs4all.nl>:

> On 8/2/2019 11:59 PM, Henning Hraban Ramm wrote:
>> Hi,
>> when I try to compile my books with lmtx, it chokes on my Lua image  
>> library. Seems like "img" (esp. img.scan) is gone. Is there a  
>> replacement?
> It depends on what you want to do ... there are some helpers and I  
> can add more if needed. There is (and already was)
>
> local t = figures.getinfo("cow.pdf")

Thank you!

I had

local pic = img.scan{filename = figures.current().status.fullname}

and actually just used pic.xsize and pic.ysize to calculate scaling  
and cropping parameters.
There’s probably an easier way to get those.

See attachment – I’m trying to calculate the image size to fit into  
the line grid.


Greetlings, Hraban
---
https://www.fiee.net
http://wiki.contextgarden.net
https://www.dreiviertelhaus.de
GPG Key ID 1C9B22FD

[-- Attachment #2: grph-imagelib.lua --]
[-- Type: text/x-lua, Size: 1774 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 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

[-- Attachment #3: Type: text/plain, Size: 493 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
___________________________________________________________________________________

  reply	other threads:[~2019-08-03  7:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02 21:59 Henning Hraban Ramm
2019-08-02 22:16 ` Hans Hagen
2019-08-03  7:02   ` Henning Hraban Ramm [this message]
2019-08-03  8:23     ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190803070229.Horde.hJ_Kt2F9cdfKVMhaPbbaELt@webmail.fiee.net \
    --to=texml@fiee.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).