Skip to content

Instantly share code, notes, and snippets.

@grubernd
Created March 16, 2015 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grubernd/d5dee2477a3a01acc9ab to your computer and use it in GitHub Desktop.
Save grubernd/d5dee2477a3a01acc9ab to your computer and use it in GitHub Desktop.
convert png to jpg while retaining the original mod date
#!/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