Add a another two examples of patterns
[PoPiPaint.git] / tools / depolar_resample_IMAGEMAGICK.sh
1 #!/bin/sh
2 #
3 # depolar_resample_IMAGEMAGICK.sh - build a pixel map for JMPrope
4 #
5 # Copyright (C) 2014  Antonio Ospite <ao2@ao2.it>
6 #
7 # This program is free software. It comes without any warranty, to
8 # the extent permitted by applicable law. You can redistribute it
9 # and/or modify it under the terms of the Do What The Fuck You Want
10 # To Public License, Version 2, as published by Sam Hocevar. See
11 # http://sam.zoy.org/wtfpl/COPYING for more details.
12
13 set -e
14
15 INPUT_WIDTH=640
16 INPUT_HEIGHT=640
17 SCALE="0.1"
18 INTERNAL_RADIUS=2
19
20 [ -f "$1" -a "x$2" != "x" ] || { echo "usage: $(basename $0) <input file> <output file> [imagemagick options]" 1>&2; exit 1; }
21
22 INPUT_FILENAME="$1"
23 shift
24
25 OUTPUT_FILENAME="$1"
26 shift
27
28 [ -e $OUTPUT_FILENAME ] && { echo "Error: $OUTPUT_FILENAME already exists, remove it first" 1>&2; exit 1; }
29
30 WIDTH=$(identify -format "%[fx:w]" "$INPUT_FILENAME")
31 HEIGHT=$(identify -format "%[fx:w]" "$INPUT_FILENAME")
32
33 if [ $WIDTH -ne $INPUT_WIDTH -o $HEIGHT -ne $INPUT_HEIGHT ];
34 then
35   echo "Error: image must be ${INPUT_WIDTH}x${INPUT_HEIGHT}" 1>&2
36   exit 1;
37 fi
38
39 CX=$(identify -format "%[fx:h/2]" "$INPUT_FILENAME")
40 CY=$(identify -format "%[fx:h/2]" "$INPUT_FILENAME")
41
42 OPTIONS="-interpolate NearestNeighbor -filter point -background black -flatten"
43
44 convert "$INPUT_FILENAME" $OPTIONS \
45   -set option:distort:scale $SCALE +distort DePolar "0 0 $CX,$CY 0,360" \
46   -flop -crop +0+$INTERNAL_RADIUS $@ +repage "$OUTPUT_FILENAME"