Created
March 16, 2015 10:42
-
-
Save grubernd/d5dee2477a3a01acc9ab to your computer and use it in GitHub Desktop.
convert png to jpg while retaining the original mod date
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 | |
#----------------------------------------------------------- | |
# Copyright (C) 2015 GRUBERND http://grubernd.at | |
# released under a FreeBSD License | |
# | |
# convert png to jpg while retaining the original mod date | |
# dependicies: imagemagick | |
#----------------------------------------------------------- | |
shopt -s nullglob nocaseglob | |
for d in *; do | |
if [ -d "$d" ]; then | |
pushd "$d" | |
echo $d | |
for f in *.png; do | |
mogrify -format jpg -- "$f" | |
j=${f%.*}.jpg | |
touch -m --date="$(stat -c %y $f)" "$j" | |
rm "$f" | |
done | |
popd | |
fi | |
done | |
#----------------------------------------------------------- | |
# same as a oneliner for insta-use: | |
# shopt -s nullglob nocaseglob; for d in *; do if [ -d "$d" ]; then pushd "$d"; echo $d; for f in *.png; do mogrify -format jpg -- "$f"; j=${f%.*}.jpg; touch -m --date="$(stat -c %y $f)" "$j"; rm "$f"; done; popd; fi; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment