mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-09 10:40:34 -05:00
JPEG compression script
This commit is contained in:
parent
bffd80ae42
commit
cc4bdc9d67
1 changed files with 37 additions and 0 deletions
37
jpg4web.bash
Executable file
37
jpg4web.bash
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 800px is the width of the content on my site
|
||||
WIDTH=800
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
show_usage() {
|
||||
echo "Usage: jpg4web.bash [imagefile]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check argument count
|
||||
if [ "$#" -ne 1 ]; then
|
||||
show_usage
|
||||
fi
|
||||
|
||||
# Check that it ends in .jpg
|
||||
if [[ "$1" != *.jpg ]]; then
|
||||
echo "Argument [imagefile] must end in .jpg"
|
||||
show_usage
|
||||
fi
|
||||
|
||||
# Check that relevant commands exist
|
||||
if ! command -v mogrify > /dev/null; then
|
||||
echo "Command magick not found. Exiting..."
|
||||
fi
|
||||
if ! command -v jpegoptim > /dev/null; then
|
||||
echo "Command jpegoptim not found. Exiting..."
|
||||
fi
|
||||
|
||||
cp "$1" "$1.bak"
|
||||
mogrify -resize "$WIDTH" "$1"
|
||||
jpegoptim "$1"
|
||||
|
Loading…
Reference in a new issue