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

[HOW-TO] Is there a way to add / update exif metadata #545

Open
mattjlewis opened this issue Jan 29, 2023 · 7 comments
Open

[HOW-TO] Is there a way to add / update exif metadata #545

mattjlewis opened this issue Jan 29, 2023 · 7 comments

Comments

@mattjlewis
Copy link

I would like to augment the JPEG image file with additional metadata, specifically GPS location and the time that the photo was taken. I can add these via e.g. exiv2 (Exif.Image.DateTime, Exif.Image.DateTimeOriginal, Exif.GPSInfo.GPSLatitudeRef, Exif.GPSInfo.GPSLatitude, Exif.GPSInfo.GPSLongitudeRef, Exif.GPSInfo.GPSLongitude), however, I cannot see a way to add directly.

I have tried altering the metadata in a pre_callback method but without luck, e.g. :

def add_metadata(request):
    metadata = request.get_metadata()
    print("In pre_callback ExposureTime: " + str(metadata["ExposureTime"]))
    metadata["DateTime"] = "2023:01:29 16:25:00"
    metadata["DateTimeOriginal"] = "2023:01:29 16:25:00"
    print("In pre_callback DateTime: " + str(metadata["DateTime"]))
    print("In pre_callback DataTimeOriginal: " + str(metadata["DateTimeOriginal"]))
@davidplowman
Copy link
Collaborator

Hi, thanks for the question. Indeed, I don't think there's a built-in way to accomplish this at the moment, and as you've discovered, you can't add arbitrary values to the image metadata and have the code understand what to do with them.

We can look into the question, but in the meantime is there a workaround where you write the JPEG to a memory buffer, then use one of Python's EXIF packages to amend it, and then re-save it to file?

@mattjlewis
Copy link
Author

Hi, thanks for the quick reply. Yes - currently doing a call out to exiv2. Would be really nice if at least DateTime / DateTimeOriginal was written by picamera2.

@davidplowman
Copy link
Collaborator

Yes, I'll certainly add the dates. For adding custom info, that probably just needs a bit of plumbing. We'll put it on the list!

@mattjlewis
Copy link
Author

Brilliant, thank you.

@davidplowman
Copy link
Collaborator

#552

@richardthegit
Copy link

I'd like to second this. The problem with patching the EXIF after file generation is that you tend to end up compressing the file twice.

@davidplowman
Copy link
Collaborator

Hi, there was a PR to add some extra functionality in this area (#786), though it seems to be a bit stalled at the moment. Although not ideal, it should be possible in the meantime to update just the exif tags using either Python or something like exiftool without re-encoding.

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

No branches or pull requests

3 participants