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
___________________________________________________________________________________

Reply via email to