ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* lmtx: img?
@ 2019-08-02 21:59 Henning Hraban Ramm
  2019-08-02 22:16 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Henning Hraban Ramm @ 2019-08-02 21:59 UTC (permalink / raw)
  To: ntg-context

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?


Greetlings, Hraban
---
https://www.fiee.net
http://wiki.contextgarden.net
https://www.dreiviertelhaus.de
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] 4+ messages in thread

* Re: lmtx: img?
  2019-08-02 21:59 lmtx: img? Henning Hraban Ramm
@ 2019-08-02 22:16 ` Hans Hagen
  2019-08-03  7:02   ` Henning Hraban Ramm
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2019-08-02 22:16 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henning Hraban Ramm

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")

Hans


-----------------------------------------------------------------
                                           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] 4+ messages in thread

* Re: lmtx: img?
  2019-08-02 22:16 ` Hans Hagen
@ 2019-08-03  7:02   ` Henning Hraban Ramm
  2019-08-03  8:23     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Henning Hraban Ramm @ 2019-08-03  7:02 UTC (permalink / raw)
  To: ntg-context

[-- 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: lmtx: img?
  2019-08-03  7:02   ` Henning Hraban Ramm
@ 2019-08-03  8:23     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2019-08-03  8:23 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henning Hraban Ramm

On 8/3/2019 9:02 AM, Henning Hraban Ramm wrote:
> 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.
hm, there's a conceptual error in there (which, lucky you, won't show up 
in your case due to some settings in context) .. i'll tell you off line

Hans

-----------------------------------------------------------------
                                           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] 4+ messages in thread

end of thread, other threads:[~2019-08-03  8:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 21:59 lmtx: img? Henning Hraban Ramm
2019-08-02 22:16 ` Hans Hagen
2019-08-03  7:02   ` Henning Hraban Ramm
2019-08-03  8:23     ` Hans Hagen

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).