pi3d / pi3d_demos

Demos and support files for pi3d (3D graphics python package for the raspberry pi)
Other
71 stars 33 forks source link

Added support for showing the taken date #28

Closed sergon2000 closed 4 years ago

sergon2000 commented 4 years ago

The script actually allows to show the file names. I have added some functionality to show also the date the photo was taken.

Let me know if you have any question :)

paddywwoof commented 4 years ago

Sergio, thanks for that. I will merge to the develop branch and test, though it looks good. (Not sure if references to base branch are new pc term for master! Not the end of the world if that happens)

paddywwoof commented 4 years ago

Went into the develop branch as expected. Good. Wolfgang was recently asking about MQTT/voice a. an option to to to next b. show the date slide was taken. So having a nice date format is great, thank again.

sergon2000 commented 4 years ago

Thanks @paddywwoof! I wanted to share with you another thought: if you go to method get_exif_info, I've noticed it's kind of common that some photos do not have orientation information so in that case the except block will overwrite the dt variable (even though it could have a valid value since the failing line is 199, the last one). The point is that maybe you should treat each exif item independently, just an idea :)

paddywwoof commented 4 years ago

Yes, good idea. I also see that there is no value set for fdt if the try block fails. Maybe we should do

def get_exif_info(file_path_name, im=None):
  dt = os.path.getmtime(file_path_name) # default file last modified date
  orientation = 1
  try:
    if im is None:
      im = Image.open(file_path_name) # lazy operation so shouldn't load (better test though)
    exif_data = im._getexif() # TODO check if/when this becomes proper function
    exif_dt = time.strptime(exif_data[EXIF_DATID], '%Y:%m:%d %H:%M:%S')
    dt = time.mktime(exif_dt)
    orientation = int(exif_data[EXIF_ORIENTATION])
  except Exception as e: # NB should really check error here but it's almost certainly due to lack of exif data
    if config.VERBOSE:
      print('trying to read exif', e)
  fdt = time.strftime(config.SHOW_TEXT_FM, time.localtime(dt))
  return (orientation, dt, fdt)