Difference between revisions of "Downsampling"

From Wiki
Jump to navigation Jump to search
(description of t-degrade)
m (outdated hint)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
Downsampling means to reduce the resolution of a picture to save space.
 
Downsampling means to reduce the resolution of a picture to save space.
  
There are two simple modules:
+
There’s a solution outlined in [[Using_Graphics#Image_Conversion]]; the rest of this page is outdated.
  
 
== grph-downsample ==
 
== grph-downsample ==
 +
 +
'''This doesn’t work any more; it was a bit better than the script in [[Using_Graphics#Image_Conversion]].'''
  
 
This MkIV module is not in the distribution and not documented, but you can download it from [http://modules.contextgarden.net/grph-downsample here]. It expects the <code>gm</code> tool from [http://www.graphicsmagick.org GraphicsMagick] to be callable and works on PNG, JPG and GIF pictures.
 
This MkIV module is not in the distribution and not documented, but you can download it from [http://modules.contextgarden.net/grph-downsample here]. It expects the <code>gm</code> tool from [http://www.graphicsmagick.org GraphicsMagick] to be callable and works on PNG, JPG and GIF pictures.
Line 50: Line 52:
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
 +
 +
 +
[[Category:Graphics]]

Latest revision as of 10:20, 12 August 2022

< Using Graphics >

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

There’s a solution outlined in Using_Graphics#Image_Conversion; the rest of this page is outdated.

grph-downsample

This doesn’t work any more; it was a bit better than the script in Using_Graphics#Image_Conversion.

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