Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renoirb
Copy link
Contributor

@renoirb renoirb commented Jun 4, 2022

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

Screen Shot 2022-06-04 at 15 46 45

Checking file dates

Screen Shot 2022-06-04 at 15 50 40

heic2jpg.sh Show resolved Hide resolved
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})
Copy link
Contributor Author

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.

@renoirb renoirb force-pushed the renoirb-perserve-creation-date branch from 6d4e4e7 to e3bcaed Compare June 4, 2022 20:02
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
Copy link
Owner

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?

Copy link
Contributor Author

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})
Copy link
Owner

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.

Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

@renoirb renoirb Jun 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants