summaryrefslogtreecommitdiff
path: root/graphics/degrade
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/degrade
Initial commit
Diffstat (limited to 'graphics/degrade')
-rw-r--r--graphics/degrade/README34
-rw-r--r--graphics/degrade/degrade.sh35
-rw-r--r--graphics/degrade/degrade.sty48
3 files changed, 117 insertions, 0 deletions
diff --git a/graphics/degrade/README b/graphics/degrade/README
new file mode 100644
index 0000000000..9eb30564e3
--- /dev/null
+++ b/graphics/degrade/README
@@ -0,0 +1,34 @@
+Description:
+------------
+This package degrades JPEG images on the fly to a given resolution to decrease
+the size of the resulting PostScript or PDF file.
+
+Requirements:
+-------------
+You'll need the convert utility from the ImageMagick bundle and the jpeg2ps
+program from CTAN if you don't use VTeX. Because of the script "degrade.sh"
+this package works only on Unix-like systems.
+
+Installation:
+-------------
+Put the script "degrade.sh" in your $PATH and make it executable.
+Put "degrade.sty" in a place where TeX can find it.
+
+Commands:
+---------
+\DegSetup{key=value,...}
+Known keys are:
+* res to set the resolution in dpi (default=100, example: res=300)
+* dir to set the directory where to put the resized jpeg files
+ (default=degrade)
+* sdir to set the directory where images should be found in general
+ (default: current directory)
+
+\degimage[w|h]{width or height}{image}
+Use this instead of \includegraphics to include your image.
+example 1: \degimage{\linewidth}{flower},
+example 2: \degimage[h]{0.5\textheight}{power}
+
+Author:
+-------
+Peter Münster, email: pmrb at free.fr
diff --git a/graphics/degrade/degrade.sh b/graphics/degrade/degrade.sh
new file mode 100644
index 0000000000..197b42a4d6
--- /dev/null
+++ b/graphics/degrade/degrade.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+## This script and the LaTeX extension "degrade.sty" may be distributed
+## under the conditions of the LaTeX Project Public License
+## (http://www.latex-project.org/lppl.txt).
+
+X=
+[ $1 = h ]&&X=x
+FORMAT="%$1"
+FILE="$5/$2.jpg"
+DFILE="$6/$2.jpg"
+DPI="$3"
+IW="$4"
+EXT="$7"
+INCH=72.27
+
+if [ -s "$FILE" ];then
+ W=`identify -format "$FORMAT" "$FILE"`
+else
+ rm -f "$DFILE"
+ exit 0
+fi
+
+NW=`echo "$DPI * $IW / $INCH"|bc`
+
+if [ $NW -ge $W ];then
+ rm -f "$DFILE"
+else
+ if [ -s "$DFILE" ]&&[ `identify -format "$FORMAT" "$DFILE"` -eq $NW ];then
+ exit 0
+ else
+ convert -verbose -resize $X$NW "$FILE" "$DFILE"
+ [ $EXT = EPS ]&&jpeg2ps "$DFILE" >"${DFILE/.jpg/.eps}"
+ fi
+fi
diff --git a/graphics/degrade/degrade.sty b/graphics/degrade/degrade.sty
new file mode 100644
index 0000000000..a4ab33e0f0
--- /dev/null
+++ b/graphics/degrade/degrade.sty
@@ -0,0 +1,48 @@
+%% degrade.sty
+%% © 2002 by Peter Münster
+%%
+%% A package, that degrades JPEG images on the fly to decrease the size of the
+%% resulting PostScript or PDF file. You'll need the convert utility from the
+%% ImageMagick bundle and the jpeg2ps program from CTAN if you don't use VTeX.
+%%
+%% It may be distributed under the conditions of the LaTeX Project Public
+%% License (http://www.latex-project.org/lppl.txt).
+%%
+%% Commands:
+%%
+%% \DegSetup{key=value,...} Known keys are:
+%% * res to set the resolution in dpi (default=100, example: res=300)
+%% * dir to set the directory where to put the resized jpeg files
+%% (default=degrade)
+%% * sdir to set the directory where images should be found in general
+%% (default: current directory)
+%%
+%% \degimage[w|h]{width or height}{image} Use this instead of \includegraphics
+%% to include your image.
+%% example 1: \degimage{\linewidth}{flower},
+%% example 2: \degimage[h]{0.5\textheight}{power}
+%%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{degrade}
+\RequirePackage{ifvtex,graphicx}
+
+%% default values:
+\newcommand*\Deg@Res{100}% 220 is good for seminar with 1024x768 display
+\newcommand*\Deg@Dir{degrade}% directory for degraded images
+\newcommand*\Deg@SDir{.}% source directory
+
+\define@key{degrade}{res}{\renewcommand*\Deg@Res{#1}}
+\define@key{degrade}{dir}{\renewcommand*\Deg@Dir{#1}}
+\define@key{degrade}{sdir}{\renewcommand*\Deg@SDir{#1}\graphicspath{{#1/}}}
+
+\newcommand*\DegSetup[1]{\setkeys{degrade}{#1}}
+\newlength\@TEMPW
+
+\ifvtex\else\def\command{\immediate\write18}\typeout{You have to run LaTeX
+ with the --shell-escape option.}\fi
+
+\newcommand\degimage[3][w]{\setlength\@TEMPW{#2}\command{degrade.sh #1 #3
+ \Deg@Res\space\strip@pt\@TEMPW\space\Deg@SDir\space\Deg@Dir\space\ifvtex
+ JPG\else EPS\fi}\if#1w\def\Deg@WH{width}\else\def\Deg@WH{height}\fi
+ \IfFileExists{\Deg@Dir/#3.jpg}{\def\Deg@File{\Deg@Dir/#3}}{%
+ \def\Deg@File{#3}}\includegraphics*[\Deg@WH=#2]{\Deg@File}}