From: Henning Hraban Ramm via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Henning Hraban Ramm <texml@fiee.net>
Subject: Re: img.scan in lmtx?
Date: Thu, 5 Aug 2021 19:00:19 +0200 [thread overview]
Message-ID: <C0DE30C2-4477-45B3-A0DE-F47FB0D4E337@fiee.net> (raw)
In-Reply-To: <b981d037-fb27-6290-1553-18e9591a42cc@xs4all.nl>
[-- 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
___________________________________________________________________________________
prev parent reply other threads:[~2021-08-05 17:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-26 22:50 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 message]
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=C0DE30C2-4477-45B3-A0DE-F47FB0D4E337@fiee.net \
--to=ntg-context@ntg.nl \
--cc=texml@fiee.net \
/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).