= Path('../data/img/22-06-11_IMG_512px.jpg')
p2img =p2img) get_date_from_file_name(path2file
datetime.datetime(2022, 6, 11, 0, 0)
image_utils
get_date_from_file_name (path2file:pathlib.Path, date_pattern:str=None)
Retrieve the date from the file name.
Returns the date encoded in the file name (as per date_pattern) as a datetime. Default date pattern is YY-MM-DD, i.g. regex ^(-(-(*
returns: date in datetime format, if found. False if not found or if file does not exist
Type | Default | Details | |
---|---|---|---|
path2file | Path | Path to the file | |
date_pattern | str | None | regex pattern for the date, if None, default date pattern is YY-MM-DD |
Returns | dt.datetime |
datetime.datetime(2022, 6, 11, 0, 0)
date_is_within_year (date, year)
True if the passed date (datetime) is within year, False otherwise
exif2dt (exif_d)
Transform a date in bytes format from EXIF into datetime format
exif_d: date in exif format, i.e. bytes. E.g. b”2018:11:21” returns: the date in datetime or False if no date is detected or not well formatted
add_missing_dates_to_exif (path2folder:pathlib.Path, year:int=None, maxhours:int=24, do_not_update_exif:bool=False, verbose:bool=False)
Add missing EXIF original and digitized dates, based on file creation or date in file name.
Type | Default | Details | |
---|---|---|---|
path2folder | Path | Path to the folder holding all jpg photos to handle | |
year | int | None | year used to filter all dates |
maxhours | int | 24 | maximum acceptable difference (in hours) between exif dates and file dates |
do_not_update_exif | bool | False | when Trud, prevent updating the exif file; used in debugging or testing |
verbose | bool | False | when True, print original, updated and retrieved updated EXIF info |
In order to better control the data changes and avoid mistaken exif updates, the process is done on a year by year basis, i.e. a specific year needs to be passed to the function and only dates within the passed year will be updated. All other dates will be disregarded.