ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* img.scan in lmtx?
@ 2020-01-26 22:50 Henning Hraban Ramm
  2020-01-27  8:16 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Henning Hraban Ramm @ 2020-01-26 22:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,
I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?

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

* Re: img.scan in lmtx?
  2020-01-26 22:50 img.scan in lmtx? Henning Hraban Ramm
@ 2020-01-27  8:16 ` Hans Hagen
  2021-07-08 18:31   ` Henning Hraban Ramm
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2020-01-27  8:16 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henning Hraban Ramm

On 1/26/2020 11:50 PM, Henning Hraban Ramm wrote:

> I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?
Just the high level command:

figures.getinfo(name,page)

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

* Re: img.scan in lmtx?
  2020-01-27  8:16 ` Hans Hagen
@ 2021-07-08 18:31   ` Henning Hraban Ramm
  2021-07-08 21:09     ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Henning Hraban Ramm @ 2021-07-08 18:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users


> Am 27.01.2020 um 09:16 schrieb Hans Hagen <j.hagen@xs4all.nl>:
> 
> On 1/26/2020 11:50 PM, Henning Hraban Ramm wrote:
> 
>> I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?
> Just the high level command:
> 
> figures.getinfo(name,page)

Coming back to this, I can’t find "figures.getinfo" in the sources. Is there any documentation?

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

* Re: img.scan in lmtx?
  2021-07-08 18:31   ` Henning Hraban Ramm
@ 2021-07-08 21:09     ` Hans Hagen
  2021-08-05 10:26       ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2021-07-08 21:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Henning Hraban Ramm

On 7/8/2021 8:31 PM, Henning Hraban Ramm wrote:
> 
>> Am 27.01.2020 um 09:16 schrieb Hans Hagen <j.hagen@xs4all.nl>:
>>
>> On 1/26/2020 11:50 PM, Henning Hraban Ramm wrote:
>>
>>> I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?
>> Just the high level command:
>>
>> figures.getinfo(name,page)

local t = figures.getinfo("name.pdf",10) -- optional page number



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

* Re: img.scan in lmtx?
  2021-07-08 21:09     ` Hans Hagen
@ 2021-08-05 10:26       ` Henning Hraban Ramm via ntg-context
  2021-08-05 15:51         ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-08-05 10:26 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm



> Am 08.07.2021 um 23:09 schrieb Hans Hagen <j.hagen@xs4all.nl>:
> 
> On 7/8/2021 8:31 PM, Henning Hraban Ramm wrote:
>>> Am 27.01.2020 um 09:16 schrieb Hans Hagen <j.hagen@xs4all.nl>:
>>> 
>>> On 1/26/2020 11:50 PM, Henning Hraban Ramm wrote:
>>> 
>>>> I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?
>>> Just the high level command:
>>> 
>>> figures.getinfo(name,page)
> 
> local t = figures.getinfo("name.pdf",10) -- optional page number

Finally coming back to this.

Since I don’t know what the function is supposed to return, I thought I’ll check:

  local image = figures.getinfo(imgname,1)
  print("TEST", image, #image)
  for k, v in ipairs(image) do
    print("TEST", oldname, k, v)
  end

but that gives only:

TEST    table: 0x7fbd4e4e1320    0

i.e. the table is empty.

Or did I misunderstand something? My Lua skills are still severely lacking...

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

* Re: img.scan in lmtx?
  2021-08-05 10:26       ` Henning Hraban Ramm via ntg-context
@ 2021-08-05 15:51         ` Hans Hagen via ntg-context
  2021-08-05 17:00           ` Henning Hraban Ramm via ntg-context
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-05 15:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen

On 8/5/2021 12:26 PM, Henning Hraban Ramm via ntg-context wrote:
> 
> 
>> Am 08.07.2021 um 23:09 schrieb Hans Hagen <j.hagen@xs4all.nl>:
>>
>> On 7/8/2021 8:31 PM, Henning Hraban Ramm wrote:
>>>> Am 27.01.2020 um 09:16 schrieb Hans Hagen <j.hagen@xs4all.nl>:
>>>>
>>>> On 1/26/2020 11:50 PM, Henning Hraban Ramm wrote:
>>>>
>>>>> I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?
>>>> Just the high level command:
>>>>
>>>> figures.getinfo(name,page)
>>
>> local t = figures.getinfo("name.pdf",10) -- optional page number
> 
> Finally coming back to this.
> 
> Since I don’t know what the function is supposed to return, I thought I’ll check:
> 
>    local image = figures.getinfo(imgname,1)
>    print("TEST", image, #image)
>    for k, v in ipairs(image) do
>      print("TEST", oldname, k, v)
>    end
> 
> but that gives only:
> 
> TEST    table: 0x7fbd4e4e1320    0
> 
> i.e. the table is empty.
> 
> Or did I misunderstand something? My Lua skills are still severely lacking...
it's a hash not an array so .... pairs


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

* Re: img.scan in lmtx?
  2021-08-05 15:51         ` Hans Hagen via ntg-context
@ 2021-08-05 17:00           ` Henning Hraban Ramm via ntg-context
  0 siblings, 0 replies; 7+ messages in thread
From: Henning Hraban Ramm via ntg-context @ 2021-08-05 17:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henning Hraban Ramm

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



> Am 05.08.2021 um 17:51 schrieb Hans Hagen <j.hagen@xs4all.nl>:
> 
> On 8/5/2021 12:26 PM, Henning Hraban Ramm via ntg-context wrote:
>>> Am 08.07.2021 um 23:09 schrieb Hans Hagen <j.hagen@xs4all.nl>:
>>> 
>>> On 7/8/2021 8:31 PM, Henning Hraban Ramm wrote:
>>>>> Am 27.01.2020 um 09:16 schrieb Hans Hagen <j.hagen@xs4all.nl>:
>>>>> 
>>>>> On 1/26/2020 11:50 PM, Henning Hraban Ramm wrote:
>>>>> 
>>>>>> I use the lua function img.scan{filename}, but in lmtx I get "attempt to index a nil value (global 'img')", so I guess this got renamed or moved?
>>>>> Just the high level command:
>>>>> 
>>>>> figures.getinfo(name,page)
>>> 
>>> local t = figures.getinfo("name.pdf",10) -- optional page number
>> Finally coming back to this.
>> Since I don’t know what the function is supposed to return, I thought I’ll check:
>>   local image = figures.getinfo(imgname,1)
>>   print("TEST", image, #image)
>>   for k, v in ipairs(image) do
>>     print("TEST", oldname, k, v)
>>   end
>> but that gives only:
>> TEST    table: 0x7fbd4e4e1320    0
>> i.e. the table is empty.
>> Or did I misunderstand something? My Lua skills are still severely lacking...
> it's a hash not an array so .... pairs

Oops. Ok, that means the information I’m looking for is in image.status.private. Who would have thought. 

Now grph-downsample.lua works with LMTX.

Hraban


[-- Attachment #2: grph-downsample.lua --]
[-- Type: application/octet-stream, Size: 3223 bytes --]

if not modules then modules = { } end modules ['grph-downsample'] = {
  version   = 1.001,
  comment   = "companion to grph-inc.mkiv",
  author    = "Peter Münster",
  copyright = "PRAGMA ADE / ConTeXt Development Team",
  license   = "see context related readme files"
}

assert(not figures.getinfo2)

figures.getinfo2 = function(name, page) -- [ [NTG-context] Pdf info with Lua/Ctx API ]
 if type(name) == "string" then
   name = { name = name, page = page }
 end

 if name.name then
   local data = figures.push(name)
   local info = figures.identify()

   if info.status.status ~= 0 then
     figures.check() -- !Counts pages here!
   end

   figures.pop()

   return --data
          info
 end
end


local format = string.format
-- figures.cachepaths.path = "cache" -- should be setup-option
local function sample_down(oldname, newname, resolution)
  print("DOWNSAMPLE sample_down " .. oldname .. " to " .. newname)
  local request = figures.current().request
  local width = request.width
  local height = request.height
  if resolution == "" then -- or (not width and not height) then
    print(format("DOWNSAMPLE Nothing to do: %s, %s, %s dpi, %s x %s px", oldname, newname, resolution, width, height))
    return
  end
  local TEXpt = 65536
  local inch = 72.27
  -- local image = img.scan{filename = oldname}
  local image = figures.getinfo(oldname,1)
  image = image.status.private
  --[[
  print("DOWNSAMPLE", image, #image)
  for k, v in pairs(image) do
    print(k, v)
  end
  width	170506321.92
  height	255759482.88
  colordepth	8
  colorspace	2
  orientation	1
  depth	0
  filename	img/09115528.jpg
  yres	72
  ysize	3888
  transform	0
  xres	72
  xsize	2592
  rotation	0
  ]]
  -- STOP
  local xy = image.xsize / image.ysize
  if (not width and not height) then
    -- no size requested? use default width
    width = 300 * TEXpt
  end
  if not width then
    height = height / TEXpt
    width = height * xy
  end
  if not height then
    width = width / TEXpt
    height = width / xy
  end
  width = math.floor(width)
  height = math.floor(height)
  print(format("DOWNSAMPLE image size %dx%dpx. requested %dx%d?", image.xsize, image.ysize, width, height))
  local xsize = math.floor(resolution * width / inch)
  local ysize = math.floor(resolution * height / inch)
  print(format("DOWNSAMPLE size %d x %d to %d x %d", image.xsize, image.ysize, xsize, ysize))
  if xsize < image.xsize or ysize < image.ysize then
    local s = format("gm convert -resize %dx%d -resample %dx%d %s %s",
                     xsize, ysize, resolution, resolution, oldname, newname)
    print("DOWNSAMPLE Conversion: " .. s)
    os.execute(s)
  else
    print(format("DOWNSAMPLE Nothing to do: %s, %s, %s dpi, %d x %d px", oldname, newname, resolution, width, height))
    -- print(format("DOWNSAMPLE Nothing to do: %s, %s, %s", oldname, newname, resolution))
    print(format("DOWNSAMPLE xsize = %d, ysize = %d", xsize, ysize))
  end
end

local formats = {"png", "jpg", "gif"}

for _, s in ipairs(formats) do
  figures.converters[s] = figures.converters[s] or {}
  figures.converters[s]["lowres." .. s] = sample_down
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] 7+ messages in thread

end of thread, other threads:[~2021-08-05 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-26 22:50 img.scan in lmtx? Henning Hraban Ramm
2020-01-27  8:16 ` Hans Hagen
2021-07-08 18:31   ` Henning Hraban Ramm
2021-07-08 21:09     ` Hans Hagen
2021-08-05 10:26       ` Henning Hraban Ramm via ntg-context
2021-08-05 15:51         ` Hans Hagen via ntg-context
2021-08-05 17:00           ` Henning Hraban Ramm via ntg-context

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