Downsampling

From Wiki
Revision as of 14:11, 8 June 2020 by Garulfo (talk | contribs)
Jump to navigation Jump to search

< Using Graphics >

Downsampling means to reduce the resolution of a picture to save space.

There are two simple modules:

grph-downsample

This MkIV module is not in the distribution and not documented, but you can download it from here. It expects the gm tool from GraphicsMagick to be callable and works on PNG, JPG and GIF pictures.

Copy grph-downsample.lua to .../texmf-local/tex/context/third/grph-downsample/grph-downsample.lua

Call context --generate

Copy hacker.jpg to your directory.

Write this to downsample.tex:

\loadluafile[grph-downsample]
\setupexternalfigures[conversion=lowres.jpg, resolution=10]
\starttext
\externalfigure[hacker.jpg][width=5cm]
\stoptext

The module extends \setupexternalfigures with the conversion and resolution keys. The former defines an extension to the filename, the latter the final resolution dpi. It works only if the width or height key of \externalfigure is defined.

conversion=lowres.jpg in the above example creates a temporary file m_k_i_v_hacker.jpg_10.lowres.jpg.


t-degrade

This MkII module is in the distribution, but also available here. It works only on JPG pictures and has some documentation.

\setupDegrade understands the keys Res, Dir, SDir:

  • Res = resolution in dpi (default: 100)
  • Dir = target directory for degraded images (default: degrade)
  • SDir = source directory of original images (default: .)

This modules works only if the if the width or height key of \externalfigure is defined. or height key of \externalfigure is defined.

It creates a Bash (shell) script and calls the tools jpeg2ps, epstopdf or texutil, identify and convert.

\usemodule[degrade]
\setupDegrade[Res=10, Dir=temp, SDir=.]
\starttext
\externalfigure[hacker.jpg][width=5cm]
\stoptext