4

I have thousands of photos in many folders. I want to batch resize them to e.g. 3000px on the longest dimension and keep the timestamp intact.

I have used the wonderfully simple tool Phatch to resize all files but the files' original timestamps are gone and there's no setting in Phatch to avoid this. So I now have a master folder with all the originals, and another folder with the Phatch results - just in case this helps.

  • Platform: Linux (Ubuntu)
  • Source files: 2000 JPG files in many subfolders
  • Target: resized to 3000px (unless already smaller than that),
    • either resize files in place
    • or save as copy using same folder structure
    • keep original file names and timestamps intact

I'm not enough of a Linux person (yet) to know what tools I could use (imagemagick? mogrify?) and how but I'll happily accept any hints!

2
  • touch supports timestamps. You still have the old files, thus you have the old filename with assorted date. It is possible to write a script using this information and touch. (But ENOTENOUGHCOFFEE so I am not writing it atm).
    – Hennes
    Jun 27, 2015 at 13:56
  • Hmm, that sounds like an evening's worth of coding to my unskilled hands. Welp, that's how I learn! Jun 27, 2015 at 13:57

2 Answers 2

5

You can do something like this, using convert from package imagemagick, putting new files in /tmp/new or a similar directory:

mkdir /tmp/new
find . -iname '*.jpg' |
while read file
do convert -resize '>3000x>3000' "$file" /tmp/new/"$file"
   touch -r "$file" /tmp/new/"$file"
done

If happy with the result, move them with:

rsync -a /tmp/new/ .
rm -fr /tmp/new
1
  • 1
    +1 for the while read file .... touch -r "$file" /tmp/new/"$file" part. That should work even with another program then convert. (or with already converted files).
    – Hennes
    Jun 27, 2015 at 14:26
2

Actually mogrify from the same package with -define preserve-timestamp=true do the same, but be carefull, this will overwrite original image.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .