Created
March 17, 2012 08:54
-
-
Save shouya/2056835 to your computer and use it in GitHub Desktop.
Resize photo to smaller scale for to upload to my wiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
extname=".jpg" | |
def_size_wid=1024 | |
new_wid=0 | |
[[ "$#" -lt "1" ]] && exit 0 | |
filename="$1" | |
[[ ! -f "$filename" ]] && { | |
echo "File not found or not a regular file." | |
exit | |
} | |
function set_file_wid { | |
wid=`exiv2 "$filename" | | |
sed -n -e '/^Image size/p' | | |
sed -e 's/.*:\s//' -e 's/\sx.*$//'` | |
hei=`exiv2 "$filename" | | |
sed -n -e '/^Image size/p' | | |
sed -e 's/.*:\s//' -e 's/^.*x\s//'` | |
if [[ "$wid" -gt "$hei" ]]; then | |
new_wid=$def_size_wid | |
else | |
new_wid=`echo $wid / \($hei / $def_size_wid\) | | |
bc -l | | |
sed 's/\..*$//'` | |
fi | |
} | |
set_file_wid | |
basename=`basename "$1" $extname` | |
oldname="$1" | |
newname="${basename}.wiki${extname}" | |
pwd | |
convert -resize $new_wid "$oldname" "$newname" # 2>/dev/null | |
if [[ "$?" == "0" ]]; then | |
echo "Done. Successfully generated $newname." | |
exit 0 | |
else | |
echo "Failed." | |
exit 1 | |
fi | |
exit | |
# Might need rename into `wikiphoto' or change the configuration to use `sync_photo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment