/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1
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
87
88
89
90
91
#!/usr/bin/env bash

___ARGS=$@

___FILE=""
___FIRST_PAGE=0
___LAST_PAGE=0
___SANITY=1
___SCALE=250
___HAS_OPTIPNG=1

function ___help () {
  echo "Convert a range of pages into pngs."
  echo "USAGE:"
  echo "    pdf2images.sh <file>.pdf <first page> <last page>"
  echo ""
}

function ___silent () {
  $@ >> /dev/null 2>&1
  return $?
}

function ___sanity_check () {
  # Check that we have the tools needed.
  ___silent which pdftoppm 

  if [ $? -gt 0 ]; then
    echo "    Can't find tool \"pdftoppm\" (Required)."
    ___SANITY=0
  fi

  ___silent which optipng
  if [ $? -gt 0 ]; then
    echo "    Can't find tool \"optpng\" (Not required)."
    ___HAS_OPTIPNG=0
  fi
  
  if [ $___SANITY -eq 0 ]; then
    echo "Please install the missing tools."
    echo ""
    exit 1
  fi
}

function ___process () {

  pdftoppm -f $___FIRST\
           -l $___LAST\
           -r $___SCALE\
           -gray\
           -png\
           -progress\
           $___FILE\
           ${___FILE%%.*}

  if [ $___HAS_OPTIPNG -eq 1 ]; then
    optipng ${___FILE%%.*}*.png
  fi
}

function ___parse_args () {
  if [ $# -eq 0 ]; then
    ___help
    exit 1
  fi
  
  ___FILE=$1
  shift
  ___FIRST=$1
  shift
  ___LAST=$1
  shift

  if [ $# -ne 0 ]; then
    echo "Nummber of arguments missmatch."
    echo ""
    ___help
    exit 1
  fi
}

function ___main () {
  ___sanity_check
  ___parse_args $___ARGS
  ___process
  exit 0
}

___main