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)?
Asked
Active
Viewed 2,519 times
2
Deepak Mittal
- 1,544
- 13
- 18
-
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. – phil294 Feb 02 '19 at 14:25
1 Answers
3
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.
exiftoolis used to find the images that need resizingconvertresizes them (doesn't touch the exif info)touch -rrestores the original timestamp from the backup file
Stéphane Chazelas
- 522,931
- 91
- 1,010
- 1,501