Kevin H
Kevin H

Reputation: 1

How do I add time/date to JP2000 metadata?

I have mosaiced satellite images to jp2000 images with the title format of mm_yys_ps.jp2 (e.g. 01_17s_ps.jp2 is from January 2017). I manually created the title with the known date, however I need to created a timeseries of this, thus I need to add the date to the metadata of the jp2000 image. I found some python code online, but it will not work for me. Does anyone know how I can add a time/date to the metadata of a jp2000 image?

from PIL import Image
from PIL.ExifTags import TAGS
import piexif
from datetime import datetime

im = Image.open("01_17s_ps.jp2")
exif_dict = piexif.load(im.info["exif"])

exif["0th"][piexif.ImageIFD.DateTime]=datetime.strptime("01_2017","%m_%Y").strftime("%m-%Y")
exif_bytes = piexif.dump(exif)
im.save(name, "jp2000", exif=exif_bytes, quality="keep", optimize=True)

p.s. this is the code I found.

Upvotes: 0

Views: 1042

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207798

I would do that with exiftool, setting the date to Christmas Day 2021 at 13:00

# pip install pyexiftool
import exiftool

# If  "exiftool" is not on your PATH, add the full path inside parentheses on next line
with exiftool.ExifTool() as et:
    et.execute(b"-datetimeoriginal=2021:12:25 13:00:00", b"image.jp2")

After you have set it, you can check it with:

exiftool image.jp2

Result

ExifTool Version Number         : 12.30
File Name                       : image.jp2
Directory                       : .
File Size                       : 131 KiB
File Modification Date/Time     : 2021:12:30 09:10:04+00:00
File Access Date/Time           : 2021:12:30 09:10:06+00:00
File Inode Change Date/Time     : 2021:12:30 09:10:04+00:00
File Permissions                : -rw-r--r--
File Type                       : JP2
File Type Extension             : jp2
MIME Type                       : image/jp2
Major Brand                     : JPEG 2000 Image (.JP2)
Minor Version                   : 0.0.0
Compatible Brands               : jp2 , jpxb, jpx
Image Height                    : 480
Image Width                     : 640
Number Of Components            : 3
Bits Per Component              : 8 Bits, Unsigned
Compression                     : JPEG 2000
Color Spec Method               : Enumerated
Color Spec Precedence           : 0
Color Spec Approximation        : Reasonable Quality
Capture Y Resolution            : 2834
Capture X Resolution            : 2834
Capture Y Resolution Unit       : m
Capture X Resolution Unit       : m
Exif Byte Order                 : Big-endian (Motorola, MM)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Y Cb Cr Positioning             : Centered
Exif Version                    : 0232
Date/Time Original              : 2021:12:25 13:00:00
Components Configuration        : Y, Cb, Cr, -
Flashpix Version                : 0100
Color Space                     : Uncalibrated
Image Size                      : 640x480
Megapixels                      : 0.307

Or, more succinctly:

exiftool -DateTimeOriginal image.jp2
Date/Time Original              : 2021:12:25 13:00:00

Upvotes: 2

Related Questions