Files
@ b996dd49a6c7
Branch filter:
Location: majic-scripts/multimedia/imgresize.sh - annotation
b996dd49a6c7
3.8 KiB
text/x-sh
Noticket: Updated help for Factorio Manager, and bumped the script version to 0.2.
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 | 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c 8fa61211042c | #!/bin/bash
#
# imgresize.sh
#
# Copyright (C) 2009, Branko Majic <branko@majic.rs>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
program="imgresize.sh"
version="0.2"
function usage() {
cat <<EOF
$program $version, a non-interactive utility for resizing the images for upload
on websites with limited space.
Usage: $program [OPTIONS] max inputDir outputDir
$program is a non-interactive utility for resizing the JPEG images for upload on
websites with limited space. It is basically a wrapper around convert utility
from ImageMagick package. All JPEG images within the input directory get
resized.
Images with heigth or width bigger than the maximum value specified get resized
along the bigger side so that it fits in the specified value. Images that do not
exceed the specified maximum value get their quality reduced.
$program accepts the following options:
-v show script version and licensing information
-h show usage help
Please report bugs and send feature requests to <branko@majic.rs>.
EOF
}
function version() {
cat <<EOF
$program, version $version
+-----------------------------------------------------------------------+
| Copyright (C) 2009, Branko Majic <branko@majic.rs> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/>. |
+-----------------------------------------------------------------------+
EOF
}
# If no arguments were given, just show usage help.
if [[ -z $1 ]]; then
usage
exit 0
fi
# Parse the arguments
while getopts "vh" opt; do
case "$opt" in
v) version
exit 0;;
h) usage
exit 0;;
*) usage
exit 1;;
esac
done
i=$OPTIND
shift $(($i-1))
max="$1"
inputDir="$2"
outputDir="$3"
for file in $(find "$inputDir" -iregex '.*jpg'); do
fileName="$(basename "$file")"
geometry="$(identify "$file" | sed -e "s#$file ##" | awk '{print $2}')"
width="$(echo "$geometry" | sed 's/x.*//')"
height="$(echo "$geometry" | sed 's/.*x//')"
if (( $width > $height && $width > $max )); then
convert -resize $max -quality 85 "$file" "$outputDir/$fileName"
elif (( $height > $width && $height > $max)); then
convert -resize x$max -quality 85 "$file" "$outputDir/$fileName"
else
convert "$file" -quality 85 "$outputDir/$fileName"
fi
done
|