ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Downsampling images (again)
@ 2024-09-21 11:21 Henning Hraban Ramm
  2024-09-21 14:30 ` [NTG-context] " Alan Braslau via ntg-context
  2024-09-22  7:06 ` Peter Münster
  0 siblings, 2 replies; 8+ messages in thread
From: Henning Hraban Ramm @ 2024-09-21 11:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

This is lying around for years, let’s try to get it finally working.
The code below works, but doesn’t do the right thing.

Since the original image doesn’t contain a resolution setting, gm 
doesn’t do anything:
“gm convert: image does not contain resolution”

It would be more reliable to use “gm convert -resize”, but for that we 
need to know the final pixel size.

How can a converter function access …
– the final (scaled) size of a placed image
– the original pixel size of an image
?
With that information it would be easy to calculate the target pixel size.

And then it would be nice to hook this function into 
\setupexternalfigure[conversion=]


"""
\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)
     logs.report("downsample", cmd)
     os.execute(cmd)
end

-- Set the PDF and default JPEG converters to the above function.
figures.converters.jpg.pdf = downsampler
figures.converters.jpg.default = downsampler
\stopluacode

\setupexternalfigure[
   %conversion=downsampler,% not used
   resolution=10,
]

\starttext

\externalfigure[https://upload.wikimedia.org/wikipedia/commons/d/dd/Hermann_Zapf_signing.jpg][width=.5\textwidth]

\stoptext
"""

Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2024-10-17 11:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-21 11:21 [NTG-context] Downsampling images (again) Henning Hraban Ramm
2024-09-21 14:30 ` [NTG-context] " Alan Braslau via ntg-context
2024-09-21 19:44   ` Henning Hraban Ramm
2024-09-23  1:48     ` Alan Braslau via ntg-context
2024-09-22  7:06 ` Peter Münster
2024-10-09 16:52   ` Henning Hraban Ramm
2024-10-16 17:59   ` Henning Hraban Ramm
2024-10-17 11:11     ` Peter Münster

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