ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Re: setupexternalfigures and resoĺution
@ 2023-07-29  1:14 Benjamin Buchmuller
  0 siblings, 0 replies; only message in thread
From: Benjamin Buchmuller @ 2023-07-29  1:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

This thread about downsampling external images on the fly is a really helpful feature! Thanks, Hraban for sharing the code!

I was wondering if it was possible to downscale also raster images embedded in pdf/svg files loaded via \externalfigure?

I found a ghostscript solution online (https://stackoverflow.com/questions/9497120/how-to-downsample-images-within-pdf-file)

gs \
-o downsampled.pdf \
-sDEVICE=pdfwrite \
-dDownsampleColorImages=true \
-dDownsampleGrayImages=true \
-dDownsampleMonoImages=true \
-dColorImageResolution=72 \
-dGrayImageResolution=72 \
-dMonoImageResolution=72 \
-dColorImageDownsampleThreshold=1.0 \
-dGrayImageDownsampleThreshold=1.0 \
-dMonoImageDownsampleThreshold=1.0 \
input.pdf

Now, I'm wondering how to adapt grph-downsample.lua to do this?

I've tried:

\setupexternalfigure[
	resolution=\Resolution, conversion=lowres.pdf
]

And added to grph-downsample.lua

local function sample_down_pdf(oldname, newname, resolution)
	print("DOWNSAMPLE sample_down " .. oldname .. " to " .. newname)
	
    -- MkIV:
    -- local image = img.scan{filename = oldname}

    -- LMTX:
    local image = figures.getinfo(oldname,1)
    image = image.status.private

    local s = format("gs \
-o \"%s\" \
-sDEVICE=pdfwrite \
-dDownsampleColorImages=true \
-dDownsampleGrayImages=true \
-dDownsampleMonoImages=true \
-dColorImageResolution=%s \
-dGrayImageResolution=%s \
-dMonoImageResolution=%s \
-dColorImageDownsampleThreshold=1.0 \
-dGrayImageDownsampleThreshold=1.0 \
-dMonoImageDownsampleThreshold=1.0 \
\"%s\"",
		oldname, resolution, resolution, resolution, newname)
					   print("DOWNSAMPLE Conversion: " .. s)
	  os.execute(s)
end

figures.converters["pdf"]["lowres." .. "pdf"] = sample_down_pdf

But I must be missing something as the code doesn't seem to be called.

Any suggestions?

Thanks!


Ben

___________________________________________________________________________________
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] only message in thread

only message in thread, other threads:[~2023-07-29  1:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-29  1:14 [NTG-context] Re: setupexternalfigures and resoĺution Benjamin Buchmuller

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