File: convert-wrapper.sh

package info (click to toggle)
tuxpaint 1%3A0.9.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,512 kB
  • sloc: ansic: 62,209; makefile: 1,425; sh: 790; objc: 303; cpp: 186; python: 182; php: 43
file content (47 lines) | stat: -rwxr-xr-x 1,209 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

# A wrapper around ImageMagick's `convert` so we can
# prevent it from using Inkscape to convert SVG files
# (which can pollute one's local filesystem with a fontcache;
# as reported by Tim Dickson, who helps maintain the
# Slackware version of the 'tuxpaint' package).
#
# Bill Kendrick <bill@newbreedsoftware.com>
# with input from Mark Kim, TOYAMA Shin-ichi, and Tim Dickson.
#
# Last modified: 2023-06-17

INPUT=`{
  shift \`expr $# - 2\`
  echo $1
}`
FILEEXT=`echo "$INPUT" | awk -F"." '{printf $NF}'`

if [ x$FILEEXT = "xsvg" ]; then
  # An SVG!

  # Create a dummy 'inkscape' that exits in such a way
  # that Imagemagick's `convert` will fallback to another
  # SVG converter, thus avoiding invoking the real Inkscape.
  echo "exit 1" > ./inkscape
  chmod +x ./inkscape
  
  # Add the local directory to the beginning of this script's
  # $PATH so `convert` finds the dummy script we just made.
  export PATH="`pwd`":"${PATH}"
  
  # Now run `convert` in the usual way (and grab its exit status,
  # so we don't catch `rm`'s)
  convert $@
  EXIT=$?
  
  # Clean up
  rm ./inkscape
else
  # Not an SVG (so, a PNG or JPEG); just run `convert` as usual.
  convert $@
  EXIT=$?
fi

exit $EXIT