aboutsummaryrefslogtreecommitdiff
path: root/img2pdf.sh
blob: cdf3f9631faaf8ab51c49919d70db178e02b78eb (plain)
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
#!/bin/bash

ext=$1
out=$2

if [ -z "$ext" ] ; then
    echo "img2pdf (png,jpg,tiff,...) (output)"
    exit
fi
if [ -z "$out" ] ; then
    out=$(basename `pwd`).pdf
fi

for img in $( echo `ls -v | egrep \."$ext"$` ) ; do
    echo Traitement de "$img"
    convert "$img" "${img:0:-$(( 1 + ${#ext})) }.pdf"
done;

if [ -e "$out" ] ; then
    echo "Gestion backup"
    set -x
    rm "$out"
    set +x
fi

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$out" `ls -v | egrep \.pdf$`

for img in *."$ext" ; do
    rm "${img:0: $(( -1 + -${#ext} )) }.pdf"
done;