Created
March 29, 2018 16:51
-
-
Save camallen/21104a4793bec9e04211e0a2f12b6171 to your computer and use it in GitHub Desktop.
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
DIRS=(local_image_directory) | |
for dir_to_process in "${DIRS[@]}" ; do | |
echo "converting files in $dir_to_process" | |
cd $dir_to_process | |
# possibly speed up using parallels? https://unix.stackexchange.com/questions/320877/how-to-use-convert-and-xargs-together | |
OUT_PATH="../converted/${dir_to_process}" | |
# this is from another project but I manually tested conversion of images to determine the following values | |
# resize to max width @ 2048 (match other sites) and 80% quality to get under 1M / 900K | |
# run some manual tests to see what works for you, e.g. | |
# convert image_file.jpg -resize 2048x -quality 90 test_output/image_file_2048_90.jpg | |
# convert image_file.jpg -resize 1024x -quality 70 test_output/image_file_1024_70.jpg | |
# etc | |
# the below relies on imagemagick convert tool | |
# https://www.imagemagick.org/script/convert.php | |
# https://serverfault.com/questions/194795/how-do-i-install-convert-on-a-linux-system | |
# find the jpegs and pass them to convert, note we pass in the outpath as positional param 2 | |
find . -type f -name '*.JPG' -exec sh -a -c 'convert "$0" -resize 2048x -quality 80 "$1/${0}"' {} $OUT_PATH \; | |
cd .. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively look at using https://squoosh.app/ or their CLI tool https://github.com/GoogleChromeLabs/squoosh/tree/dev/cli for image optimzation and resizing.