Last active
August 31, 2017 15:27
-
-
Save joahking/7c8c03783052d9eb7e65215d0bb9229f to your computer and use it in GitHub Desktop.
Bash script used in ifeelmaps.com to compare image sizes
This file contains hidden or 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 | |
# Compare every file passed over stdin with it's converted one | |
# i.e. file.extension vs file_imagemagick_converted.extension and echo the bigger one of each pair | |
# | |
# Usage: | |
# ./compare-imgs.sh < converted_images > bigger_imgs | |
# | |
# Arguments: | |
# stdin - list of filenames | |
suffix=imagemagick_converted # the suffix used to generate converted images | |
while read -r filename; # loop over filenames passed over stdin | |
do | |
dot_index=`expr index $filename .` # find the dot index in filename | |
name=${filename:0:dot_index-1} # characters before the dot | |
extension=${filename:dot_index} # characters after the dot | |
converted="$name"_"$suffix".$extension | |
if [ -e "$converted" ] # converted image exists? | |
then | |
size_original=`stat -c%s $filename` | |
size_converted=`stat -c%s $converted` | |
if [[ $size_original -gt $size_converted ]]; then | |
echo $filename # original is bigger | |
else | |
echo $converted # converted is bigger | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment