Created
September 18, 2023 14:25
-
-
Save safferli/44b4c83f8af407a090ba808c8fec4daf to your computer and use it in GitHub Desktop.
rename szi images to make them easily imagemagick-able
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/zsh | |
# szi file[1] setup is: | |
# | |
# col_row.jpg | |
# | |
# for imagemagick we want: | |
# | |
# row_col.jpg | |
# | |
# and make sure to pad numbers for lexicographical sorting. | |
# | |
# [1] https://github.com/smartinmedia/SZI-Format | |
for file in *.jpg; do | |
# =~ is the regex matching operator in zsh | |
if [[ $file =~ ^([0-9]+)_([0-9]+)\.jpg$ ]]; then | |
col=${match[1]} | |
row=${match[2]} | |
# Pad col and row with leading zeros to ensure triple digits sorting | |
col=$(printf "%03d" $col) | |
row=$(printf "%03d" $row) | |
# swap col and row, and add r_, c_ to make sure files don't overwrite each other | |
new_file="r${row}_c${col}.jpg" | |
cp "$file" "$new_file" | |
echo "Renamed $file to $new_file" | |
fi | |
done | |
# call imagemagick with: | |
# magick montage -mode concatenate -tile 82x r*.jpg ../montage.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment