Last active
March 25, 2021 19:58
-
-
Save chiqui3d/1e8786203d045626e34938fc0d7793dd to your computer and use it in GitHub Desktop.
Resize and compress in Bulk with Google's image recommendations with the super ImageMagick
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
# Search for images in any directory where the script is executed $(pwd) and compress and resize them | |
# Change to your liking | |
# echo $1 # parameter | |
# echo $(pwd); # current directory where script is run | |
find "$(pwd)" \( -iname \*.jpg -o -iname \*.jpeg \) -print0 | while read -r -d $'\0' file; do | |
name="${file##*/}" # Name with extension | |
directory="${file%/*}" # Image directory without image name :) | |
newname="$(echo $name | sed 's/ /-/g' | awk '{print tolower($0)}')" # Image name without spaces and lower | |
# $finalname: New output path. | |
# $finalname: The resize folder has been added in the output path so as not to replace the original image, | |
# $finalname: Also I have added a prefix to the name that is related to my product. | |
finalname=$directory/resize/mamparas-oficina-$newname | |
mkdir -p "$directory/resize" # Make new resize directory | |
# convert is from imagemagick https://imagemagick.org/script/convert.php | |
# $file: Is the current image path from loop | |
convert "$file" -monitor -sampling-factor 4:2:0 -strip -interlace JPEG -colorspace sRGB -resize 1000 -compress JPEG -quality 80 "$finalname" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment