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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions heic2jpg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

src=$1
size=$(find $src -type f | grep -i '\.heic$' | wc -l)
cnt=0
iter=0

for i in $(find $src -type f | grep -i '\.heic$')
for fn in $(find $src -type f | grep -i '\.heic$')
do
((cnt=cnt+1))
target=$(echo $i | sed 's/heic$/jpg/i')
printf "$i convert to $target\n"
/usr/bin/convert $i $target
printf " [$cnt/$size]\r"
iter=$((iter+1))
dhlavaty marked this conversation as resolved.
Show resolved Hide resolved
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

printf "$iter/$size:\n"
printf " File: $fn\n"
printf " Creation date: $FILE_DATE\n"
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

printf "\n\r"
done

printf "\n=== Finished ===\n"