-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: get the creation date from original, set to converted #2
base: main
Are you sure you want to change the base?
Conversation
heic2jpg.sh
Outdated
target=$(echo $i | sed 's/heic$/jpg/i') | ||
printf "$i convert to $target\n" | ||
# https://www.tutorialkart.com/bash-shell-scripting/bash-date-format-options-examples/ | ||
FILE_DATE=$(/bin/date +%Y%m%d%H%M.%S -r ${target}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format looks like this 202001100851.47
, which is for 2020-01-10 08:51:47
, a format accepted by touch
to set the new date. This doesn't take the Time Zone into account, but at least the converted file will be much closer to the original creation date than the time of creation of the converted file.
6d4e4e7
to
e3bcaed
Compare
printf " Convert as file: $target\n" | ||
/usr/bin/convert $fn $target | ||
# Set the same date as the original image | ||
/bin/touch -a -m -t $FILE_DATE $target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had time to try it, but isn't touch -r
exactly for that? For copying date from one file to another?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure touch can use date from another file.
But date can read, and extract in any format, so that's what I did.
Now that you raise the idea that maybe touch can be used. I'm curious
iter=$((iter+1)) | ||
target=$(echo $fn | sed 's/heic$/jpg/i') | ||
# https://www.tutorialkart.com/bash-shell-scripting/bash-date-format-options-examples/ | ||
FILE_DATE=$(/bin/date +%Y%m%d%H%M.%S -r ${fn}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we get the date&time from the EXIF instead? That would make more sense to me than relying on the file system itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In different script of mine, I successfully used the exiv2
tool for similar thing.
In this case running exiv2 -T -F rename *.jpg
would do the trick. Wouldn't it be worth adding this to the docker image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file date is used by other photos management apps. Let's make sure we set the file date as the original created date, or use EXIF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if you got me right. I think the creation date of JPG file should be set from EXIF, rather than copying it from creation date of HEIF file.
That is exactly what exiv2 -T -F rename *.jpg
is doing. It will go thru all *.jpg files, reads the date from EXIF, and sets it to the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
What I'm saying is that it depends of the photo management system. There are two places where the date is stored. Some uses the filesystem creation date, others from EXIF. Let's make both of them have the same date.
Let's make the converted file to have the same date at both places. AVOID having the converted file to have created date of today.
I'll adjust my PR
When converting files, it is likely because we want to import into a photo management system. We might still want to have the original date of creation. This reads the date, and sets it on the new converted image.
Screenshots
Running output
Checking file dates