-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxpect
executable file
·38 lines (34 loc) · 1.34 KB
/
maxpect
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
#!/bin/sh
# A simple script to resize all pictures, passed on the command line, to
# a maximum size, preserving aspect ratio and EXIF information.
# By default, the maximum size is 1920x1920. ImageMagick will take the
# higher of the two dimensions, so a 2000x1500 image will be scaled to
# 1920x1440 to preserve aspect ratio. A different size can be passed
# through the environment, e.g.
# env TARGET_RES=700x700 maxpect img_02*.jpg
# Resized files are not renamed, and are saved in a directory "maxpect"
# (or whatever MAXPECT_OUTDIR is set to; the directory which will be created
# if necessary).
# The script will try to set the modification time to the timestamp from
# the EXIF information, or if that's not available, it tries to preserve
# the mtime from the original file.
# Requires the imagemagick and jhead packages.
target_res=${TARGET_RES:-"1920x1920"}
outdir=${MAXPECT_OUTDIR:-"maxpect"}
ionice -n 7 -c 2 -p $$
renice 10 $$
[ -d "$outdir" ] || mkdir "$outdir"
maxpect() {
file="$1"
quality=`identify -verbose "$file" | grep '^ *Quality:' | awk '{print $2}'`
jpeg_quality=""
if [ -n "$quality" ] && [ $quality -gt 85 ] ; then
jpeg_quality="-quality 85"
fi
convert "$file" -resize "$target_res>" $jpeg_quality "$outdir"/"$file"
jhead -ft "$outdir"/"$file" > /dev/null || touch -r "$file" "$outdir"/"$file"
}
for a in "$@"
do
maxpect "$a"
done