Last active
December 8, 2020 08:07
-
-
Save jameslafa/840833d8ba31567e4dc25f183141a35b to your computer and use it in GitHub Desktop.
Script to square pictures, add a white border and resize them to 1200px for instagram
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 | |
for dir in */ ; do | |
# Check if there are images in the folder before moving forward | |
if [[ $(find $dir -maxdepth 1 -type f -name "*.jpg"| wc -l) -ge 1 ]]; then | |
# If there is already an instagram folder in this folder, I skip. | |
if [[ ! -d "$dir"instagram ]]; then | |
mkdir "$dir"instagram | |
fi | |
for file in "$dir"*.jpg ; do | |
filename="${file##*/}" | |
if [[ -f "$dir"/instagram/"$filename" ]]; then | |
continue | |
fi | |
# Get picture dimentions (w & h) | |
#IFS=" x+" read w h x y < <(convert -fuzz 10% "$file" -format "%@" info:) | |
IFS=" x+" read w h x y < <(convert "$file" -format "%@" info:) | |
# Get longest side | |
longest=$w | |
[ $h -gt $longest ] && longest=$h | |
# Add 10% border | |
longest=$(echo "scale=0;$longest*1.05/1" | bc) | |
pic="$dir"instagram/$(basename "$file") | |
echo "$pic" # to see the progress | |
# convert -fuzz 10% "$file" -trim -background white -gravity center -extent ${longest}x${longest} "$pic" | |
convert "$file" -trim -background white -gravity center -extent ${longest}x${longest} -resize 1200x1200 "$pic" | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of the result