I wanted to watch a movie yesterday, but my Xbox's fans are too loud. So I decided to do something about it!
Monday, September 2, 2013
Batch photo resize preserving modify date
On Mac OS with ImageMagick installed (see also this older post):
mkdir resized
cp 2013-09-02*.jpg resized
mogrify -resize 3056x3056 resized/*.jpg
find resized -name "*.jpg" | sed "s/resized\///" | xargs -I {} touch -r "{}" "resized/{}"
mv resized/*.jpg .
rmdir resized
The crazy find/sed/xargs thing does the following:
mkdir resized
cp 2013-09-02*.jpg resized
mogrify -resize 3056x3056 resized/*.jpg
find resized -name "*.jpg" | sed "s/resized\///" | xargs -I {} touch -r "{}" "resized/{}"
mv resized/*.jpg .
rmdir resized
The crazy find/sed/xargs thing does the following:
- find : Find all the jpg files in the "resized" folder and return their relative path.
- sed : Find and replace all instances of "resized/" with an empty string. sed returns the full string with replacements, not just the match.
- xargs touch : Change each of the files in the "resized" folder to have the same modify date
Subscribe to:
Posts (Atom)