I have a huge collection of family photos which I don't really need full resolution of. I want to use mogrify but I tried it on a sample set of images and it seems that it sets modification time of files to current time. Is there any way to preserve modification/create time of original image (for both EXIF data and linux's native file modification times which you can view using stat)?

  • maybe you can use jpegoptim instead which includes a -p option that preserves modification time. jpegoptim is good at reducing file size, but as the name suggests, only works for jpgs. For pngs, I use a workaround like below answer too. – Blauhirn Feb 2 at 14:25

You could always do it with a bit of scripting:

exiftool  -q -r -ext jpg -if '
    $ImageWidth > 1000 ||
    $ImageHeight > 1000 and
      !print "$Directory/$Filename\0"' . |
  xargs -r0 sh -c '
    for file do
      mv -i "$file" "$file.back" &&
        convert -resize "1000x1000>" "$file.back" "$file" &&
        touch -r "$file.back" "$file"
    done' sh

Here resizing the images so they fit into a bounding box of 1000x1000.

  • exiftool is used to find the images that need resizing
  • convert resizes them (doesn't touch the exif info)
  • touch -r restores the original timestamp from the backup file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.