-
Notifications
You must be signed in to change notification settings - Fork 4
/
cpimg
executable file
·86 lines (72 loc) · 1.64 KB
/
cpimg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /bin/sh
#
# Copy an image from SRC to DST, transforming it along the way such that
# it is suitable to be used in Latex.
#
# INVOCATION
#
# $0 SRC DST
#
# SEE ALSO
#
# This code is based on the file "mkimg" from Jérôme Kunegis' PhD
# thesis.
#
# TO DO
#
# Support more formats -- see svn/kunegis/papers/phd/mkimg for code.
#
# ABOUT
#
# Written by Jérôme Kunegis.
#
set -e
if [ -z "$1" -o -z "$2" ] ; then
echo >&2 "*** Filenames missing"
exit 1
fi
src="$1"
dst="$2"
# Threshold filesize for converting a file to bitmap
FILESIZE_THRESHOLD=500000
if [ -z "$TMPDIR" ] ; then
TMPDIR=/tmp
fi
if [ ! -e "$src" ] ; then
echo >&2 "$0: *** Source file '$src' must exist"
exit 1
fi
if echo "$src" | grep -qE '\.eps$' ; then
if echo "$dst" | grep -qE '\.pdf$' ; then
if [ "$(stat -c %s $src)" -lt "$FILESIZE_THRESHOLD" ] ; then
epstopdf "$src" --outfile="$dst"
else
convert "$src" -resize 100% "$dst"
fi
else
echo >&2 "*** Unknown destination file type for EPS source: '$dst'"
exit 1
fi
elif echo "$src" | grep -qE '\.svg$' ; then
if echo "$dst" | grep -qE '\.pdf$' ; then
inkscape -z "$src" -A "$dst"
if [ "$(stat -c %s $dst)" -ge "$FILESIZE_THRESHOLD" ] ; then
cp "$dst" "$TMPDIR"/"$$".pdf
convert "$TMPDIR"/"$$".pdf -resize 100% "$dst"
fi
else
echo >&2 "*** Unknown destination file type for SVG source: '$dst'"
exit 1
fi
elif echo "$src" | grep -qE '\.pdf$' ; then
if echo "$dst" | grep -qE '\.eps$' ; then
inkscape -z "$src" -E "$dst"
else
echo >&2 "*** Unknown destination file type for PDF source: '$dst'"
exit 1
fi
else
echo >&2 "*** Unknown source file type: '$src'"
exit 1
fi
exit 0