* access image properties in Lua
@ 2023-07-11 12:22 Henning Hraban Ramm
2023-07-13 7:19 ` Hans Hagen
0 siblings, 1 reply; 6+ messages in thread
From: Henning Hraban Ramm @ 2023-07-11 12:22 UTC (permalink / raw)
To: mailing list for ConTeXt users
What’s the current approved way to get image properties within a Lua
function?
very old:
local pic = figures.getinfo(figures.current().status.fullname)
used to work in 2019:
local pic = img.scan{filename = figures.current().status.fullname}
if I understand this right, "img" isn’t valid anymore:
"""
token call, execute: grph-imagelib.lua:37: attempt to index a nil value
(global 'img')
"""
I’d like to know the pixel size and if possible also the scaled target
size of an image; either the "current" one or by name.
Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: access image properties in Lua
2023-07-11 12:22 access image properties in Lua Henning Hraban Ramm
@ 2023-07-13 7:19 ` Hans Hagen
2023-07-17 13:44 ` [NTG-context] " Alan Braslau via ntg-context
0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2023-07-13 7:19 UTC (permalink / raw)
To: ntg-context
On 7/11/2023 2:22 PM, Henning Hraban Ramm wrote:
> What’s the current approved way to get image properties within a Lua
> function?
>
> very old:
> local pic = figures.getinfo(figures.current().status.fullname)
>
> used to work in 2019:
> local pic = img.scan{filename = figures.current().status.fullname}
>
> if I understand this right, "img" isn’t valid anymore:
> """
> token call, execute: grph-imagelib.lua:37: attempt to index a nil value
> (global 'img')
> """
>
> I’d like to know the pixel size and if possible also the scaled target
> size of an image; either the "current" one or by name.
\ctxlua{inspect(figures.getinfo("t:/sources/mill.png").used)}
\ctxlua{inspect(figures.getinfo("t:/sources/mill.png").status)}
etc .. no more faking the img lib
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 / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: access image properties in Lua
2023-07-13 7:19 ` Hans Hagen
@ 2023-07-17 13:44 ` Alan Braslau via ntg-context
2023-07-17 16:20 ` Henning Hraban Ramm
0 siblings, 1 reply; 6+ messages in thread
From: Alan Braslau via ntg-context @ 2023-07-17 13:44 UTC (permalink / raw)
To: mailing list for ConTeXt users, Hans Hagen; +Cc: Alan Braslau
On 13/07/23 13/07/23, 09:19, Hans Hagen wrote:
> On 7/11/2023 2:22 PM, Henning Hraban Ramm wrote:
>> What’s the current approved way to get image properties within a Lua
>> function?
>>
>> very old:
>> local pic = figures.getinfo(figures.current().status.fullname)
>>
>> used to work in 2019:
>> local pic = img.scan{filename = figures.current().status.fullname}
>>
>> if I understand this right, "img" isn’t valid anymore:
>> """
>> token call, execute: grph-imagelib.lua:37: attempt to index a nil
>> value (global 'img')
>> """
>>
>> I’d like to know the pixel size and if possible also the scaled target
>> size of an image; either the "current" one or by name.
> \ctxlua{inspect(figures.getinfo("t:/sources/mill.png").used)}
>
> \ctxlua{inspect(figures.getinfo("t:/sources/mill.png").status)}
>
> etc .. no more faking the img lib
>
> Hans
Hraban, Hans, and mailing list.
This is interesting. I would find it useful to be able to report these
properties though a tracker - should be fairly easy if not already
available.
One works with images having a certain resolution, whatever that may be.
We also might have a target resolution, say 300 dpi or perhaps better
for printing. As the images are typically resized when used, the
resulting resolutions might be anything. Optimizing the resolutions of
the source images can result in optimal PDF sizes, i.e. not too high nor
too low resolution.
I can even imagine an automated workflow where high-resolution, say 2400
dpi or even greater bitmap images, are supplied and the included bitmap
could be "resampled" resulting in the inclusion of a targeted
resolution. However, the reporting of the included, likely resized image
resolutions then used to adjust or resample the source files externally
and manually case-by-case would be sufficient.
Any suggestions on how to hook-in such reporting?
Bonus question: how also to handle the case of
\startMPcode
draw figure "MyFigure" xsized TextWidth ;
...
\stopMPcode
--
Alan
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: access image properties in Lua
2023-07-17 13:44 ` [NTG-context] " Alan Braslau via ntg-context
@ 2023-07-17 16:20 ` Henning Hraban Ramm
2023-07-17 17:10 ` Alan Braslau via ntg-context
[not found] ` <048d051e-c66f-3e0f-e3d2-48ef300b7280@icloud.com>
0 siblings, 2 replies; 6+ messages in thread
From: Henning Hraban Ramm @ 2023-07-17 16:20 UTC (permalink / raw)
To: ntg-context
Am 17.07.23 um 15:44 schrieb Alan Braslau via ntg-context:
> On 13/07/23 13/07/23, 09:19, Hans Hagen wrote:
>> On 7/11/2023 2:22 PM, Henning Hraban Ramm wrote:
>>> What’s the current approved way to get image properties within a Lua
>>> function?
>>> I’d like to know the pixel size and if possible also the scaled
>>> target size of an image; either the "current" one or by name.
>> \ctxlua{inspect(figures.getinfo("t:/sources/mill.png").used)}
>>
>> \ctxlua{inspect(figures.getinfo("t:/sources/mill.png").status)}
>>
>> etc .. no more faking the img lib
Thank you!
> We also might have a target resolution, say 300 dpi or perhaps better for printing.
What raster widths are you printing with?
More than 300 dpi would be only needed for very high resolution art
prints with very fine details, possibly in FM raster.
Usually, 200 dpi final resolution is enough – 300 dpi are suggested to
allow for some scaling.
For fine line art (black or spot color only, no rastering), 1200 dpi is
suggested.
> I can even imagine an automated workflow where high-resolution, say 2400
> dpi or even greater bitmap images, are supplied and the included bitmap
> could be "resampled" resulting in the inclusion of a targeted
> resolution. However, the reporting of the included, likely resized image
> resolutions then used to adjust or resample the source files externally
> and manually case-by-case would be sufficient.
Well, I was working for years with adapted versions of Peter Münster’s
graph-downsample.lua.
You can hook in custom functions like this:
"""
\startluacode
local function downsampler(oldname, newname, resolution)
if not resolution or resolution == "" then
resolution = 72
end
local cmd = string.format(
[[gm convert -resample %ix%i %s %s]],
resolution, resolution, oldname, newname)
--print(cmd)
os.execute(cmd)
end
-- Beware: the calculation is still wrong,
-- I need to try figures.getinfo
-- Set the PDF and default JPEG converters to the above function.
--figures.converters.jpg.downsampler = downsampler
figures.converters.jpg.pdf = downsampler
figures.converters.jpg.default = downsampler
\stopluacode
\setupexternalfigure[
conversion=downsampler,
resolution=200,
]
"""
> Any suggestions on how to hook-in such reporting?
local report = logs.reporter("alan.imaging")
report("Now calculating...")
> Bonus question: how also to handle the case of
> \startMPcode
> draw figure "MyFigure" xsized TextWidth ;
> ...
> \stopMPcode
Is MyFigure a pixel image?
You could use \externalfigure within MP code.
Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: access image properties in Lua
2023-07-17 16:20 ` Henning Hraban Ramm
@ 2023-07-17 17:10 ` Alan Braslau via ntg-context
[not found] ` <048d051e-c66f-3e0f-e3d2-48ef300b7280@icloud.com>
1 sibling, 0 replies; 6+ messages in thread
From: Alan Braslau via ntg-context @ 2023-07-17 17:10 UTC (permalink / raw)
To: mailing list for ConTeXt users, Henning Hraban Ramm; +Cc: Alan Braslau
On 17/07/23 17/07/23, 18:20, Henning Hraban Ramm wrote:
>> Bonus question: how also to handle the case of
>> \startMPcode
>> draw figure "MyFigure" xsized TextWidth ;
>> ...
>> \stopMPcode
>
> Is MyFigure a pixel image?
> You could use \externalfigure within MP code.
The MP operator figure calls \externalfigure.
However, the resolution downsampler hooked into externalfigure as you
suggest would not give the desired resolutions once resized in MP.
A solution might be to use
draw rawtextext("\externalfigure[MyFigure][width=\textwidth") ;
which is OK for this simplified example but would not work when more
sophisticated MetaPost transformations might be needed.
Along the lines of the conversion downsampler, a resolution reporter and
manual resampling could be more efficient than reconverting the bitmap
image at every run, of which there can be many.
--
Alan
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
* [NTG-context] Re: access image properties in Lua
[not found] ` <048d051e-c66f-3e0f-e3d2-48ef300b7280@icloud.com>
@ 2023-07-18 11:39 ` Henning Hraban Ramm
0 siblings, 0 replies; 6+ messages in thread
From: Henning Hraban Ramm @ 2023-07-18 11:39 UTC (permalink / raw)
To: mailing list for ConTeXt users
(I assume you didn’t reply privately on purpose and take this back to
the mailing list.)
Am 18.07.23 um 12:47 schrieb Alan Braslau:
> P.S. I have not used the built-in resolution= image conversion (using
> gm/ImageMagik). I imagine that ConTeXt is clever enough to store the
> converted file so that it only need to be converted once. However, is
> the resolution resampled before or after size conversion in
> \externalfigure?
If Hans didn’t add it recently, there‘s no automatical downsampling in
ConTeXt (yet), that’s why I want to do this; the resolution parameter is
apparently never used.
Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-18 11:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-11 12:22 access image properties in Lua Henning Hraban Ramm
2023-07-13 7:19 ` Hans Hagen
2023-07-17 13:44 ` [NTG-context] " Alan Braslau via ntg-context
2023-07-17 16:20 ` Henning Hraban Ramm
2023-07-17 17:10 ` Alan Braslau via ntg-context
[not found] ` <048d051e-c66f-3e0f-e3d2-48ef300b7280@icloud.com>
2023-07-18 11:39 ` Henning Hraban Ramm
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).