File: geeqie-resize-image

package info (click to toggle)
geeqie 1%3A2.5-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 16,780 kB
  • sloc: cpp: 110,189; xml: 11,497; sh: 3,681; awk: 124; perl: 88; python: 80; makefile: 23
file content (145 lines) | stat: -rwxr-xr-x 4,465 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh

## @file
## @brief Resize an image to a specified value.
##
## Requires:
## yad
## ImageMagick
##

current_dir=$(dirname "$(readlink -f "$0")")

if ! command -v yad > /dev/null
then
	zenity --window-icon=/usr/local/share/pixmaps/geeqie.png --width=400 --info --title "Geeqie Resize" --text="yad and ImageMagick are required\n\nyad is not installed"
	exit 0
fi

if ! command -v convert > /dev/null
then
	zenity --window-icon=/usr/local/share/pixmaps/geeqie.png --width=400 --info --title "Geeqie Resize" --text="yad and ImageMagick are required\n\nImageMagick is not installed"
	exit 0
fi

if [ -z "$1" ]
then
	yad --window-icon=/usr/local/share/pixmaps/geeqie.png --geometry=400 --image dialog-warning --title "Geeqie Resize" --button=gtk-ok:0 --text "\nNo input file was given."
	exit 0
fi

basefile=$(basename "$1")
base=${basefile%.*}
ext=${basefile#*.}

default_filename=$(printf %s "/tmp/$base-resized.$ext")
if [ -f "$default_filename" ]
then
	i=1
	while true
	do
		default_filename=$(printf %s%d%s "/tmp/$base-resized-" "$i" ".$ext")
		if [ -f "$default_filename" ]
		then
			i=$(( i + 1 ))
		else
			break
		fi
	done
fi


selection=$(yad --window-icon=/usr/local/share/pixmaps/geeqie.png \
--center                                                          \
--title="Resize $1"                                               \
--button=gtk-help:"$current_dir"/resize-help.sh                   \
--button=gtk-cancel:1                                             \
--button=gtk-ok:0                                                 \
--text="<b>Reduce image size:</b>\n"                              \
--form                                                            \
--field="Required size kB":NUM           '100!1..100000!1!'       \
--field="Tolerance %":NUM                '10!1..100!1!'           \
--field="Max. iterations":NUM            '20!1..100!1!'           \
--field="Copy if unchanged":CHK          'FALSE'                  \
--field="Strip metadata":CHK             'TRUE'                   \
--field="Show computation":CHK           'FALSE'                  \
--field="Open output file in Geeqie":CHK 'FALSE'                  \
--field="":LBL                                                    \
--field="Output file":SFL                                         \
--field="Default: $default_filename":LBL )

if [ -z "$selection" ]
then
	exit 0
fi

size=$(printf %s "$selection" | cut --delimiter="|" --fields=1 -)
tolerance=$(printf %s "$selection" | cut --delimiter="|" --fields=2 -)
iterations=$(printf %s "$selection" | cut --delimiter="|" --fields=3 -)
copy_unchanged=$(printf %s "$selection" | cut --delimiter="|" --fields=4 -)
strip_metadata=$(printf %s "$selection" | cut --delimiter="|" --fields=5 -)
show_computation=$(printf %s "$selection" | cut --delimiter="|" --fields=6 -)
open_geeqie=$(printf %s "$selection" | cut --delimiter="|" --fields=7 -)
file=$(printf %s "$selection" | cut --delimiter="|" --fields=9 -)

if [ -z "$file" ]
then
	new_filename="$default_filename"
else
	if [ -f "$file" ]
	then
		if ! yad --window-icon=/usr/local/share/pixmaps/geeqie.png --geometry=300 --image dialog-warning --title "Geeqie Resize" --text "\nOutput file already exists.\nOverwrite?"
		then
			exit 0
		fi
	fi
	new_filename="$file"
fi

if [ "$copy_unchanged" = "FALSE" ]
then
	copy="n"
else
	copy="y"
fi

if [ "$strip_metadata" = "FALSE" ]
then
	strip="n"
else
	strip="y"
fi

tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")

yad --window-icon=/usr/local/share/pixmaps/geeqie.png --geometry=300 --image dialog-information --title "Geeqie Resize" --button=OK:0 --text "Running Downsize...." &
info_id="$!"

result=$("$current_dir"/downsize -s "$size" -t "$tolerance" -m "$iterations" -c "$copy" -S "$strip" "$1" "$new_filename" > "$tmp_file" 2>/dev/null)

if [ "$?" -eq 1 ]
then
	kill "$info_id"
	rm "$tmp_file"

	yad --window-icon=/usr/local/share/pixmaps/geeqie.png --geometry=400 --image dialog-warning --title "Geeqie Resize" --button=gtk-ok:0 --text "Downsize failed.\n\nIf the filetype is not supported by Downsize,\ntry the Export plugin to get a jpeg.\n\nDownsize error message:\n$result"
	exit 0
fi

kill "$info_id"

if [ "$open_geeqie" = "TRUE" ]
then
	geeqie --remote "$new_filename"
fi


if [ "$show_computation" = "TRUE" ]
then
	yad --window-icon=/usr/local/share/pixmaps/geeqie.png --title "Geeqie Resize computation" --text="$new_filename\n\n$(cat "$tmp_file")" --button=gtk-ok:0
fi

rm "$tmp_file"

exit 0