<%doc> This is an example Mako template for use with --sidecar-template which produces an XMP sidecar file For more information on Mako templates, see https://docs.makotemplates.org/en/latest/ The template will be passed three variables for rendering: photo: a PhotoInfo object for the photo being exported photo_path: a pathlib.Path object for the photo file being exported sidecar_path: a pathlib.Path object for the sidecar file being written <%def name="photoshop_sidecar_for_extension(extension)"> % if extension is None: % else: ${extension} % endif <%def name="dc_description(desc)"> % if desc is None: % else: ${desc | x} % endif <%def name="dc_title(title)"> % if title is None: % else: ${title | x} % endif <%def name="dc_subject(subject)"> % if subject: % for subj in subject: ${subj | x} % endfor % endif <%def name="dc_datecreated(date)"> % if date is not None: ${date.isoformat()} % endif <%def name="iptc_personinimage(persons)"> % if persons: % for person in persons: ${person | x} % endfor % endif <%def name="dk_tagslist(keywords)"> % if keywords: % for keyword in keywords: ${keyword | x} % endfor % endif <%def name="adobe_createdate(date)"> % if date is not None: ${date.strftime("%Y-%m-%dT%H:%M:%S")} % endif <%def name="adobe_modifydate(date)"> % if date is not None: ${date.strftime("%Y-%m-%dT%H:%M:%S")} % endif <%def name="xmp_rating(rating)"> % if rating is not None: ${rating} % endif <%def name="gps_info(latitude, longitude)"> % if latitude is not None and longitude is not None: ${int(abs(longitude))},${(abs(longitude) % 1) * 60}${"E" if longitude >= 0 else "W"} ${int(abs(latitude))},${(abs(latitude) % 1) * 60}${"N" if latitude >= 0 else "S"} % endif <%def name="mwg_face_regions(photo)"> % if photo.face_info: ${photo.width if photo.orientation in [5, 6, 7, 8] else photo.height} ${photo.height if photo.orientation in [5, 6, 7, 8] else photo.width} pixel % for face in photo.face_info: ${'{0:.6f}'.format(face.mwg_rs_area.h)} ${'{0:.6f}'.format(face.mwg_rs_area.w)} ${'{0:.6f}'.format(face.mwg_rs_area.x)} ${'{0:.6f}'.format(face.mwg_rs_area.y)} normalized ${face.name} ${face.roll} Face % endfor % endif <%def name="mpri_face_regions(photo)"> % if photo.face_info: % for face in photo.face_info: ${face.name} ${'{0:.6f}'.format(face.mpri_reg_rect.x)}, ${'{0:.6f}'.format(face.mpri_reg_rect.y)}, ${'{0:.6f}'.format(face.mpri_reg_rect.h)}, ${'{0:.6f}'.format(face.mpri_reg_rect.w)} % endfor % endif <% extension = photo_path.suffix[1:].lower() if photo_path.suffix else "" %> ${photoshop_sidecar_for_extension(extension)} ${dc_description(photo.description)} ${dc_title(photo.title)} <% subjects = photo.keywords + photo.persons %> ${dc_subject(subjects)} ${dc_datecreated(photo.date)} ${iptc_personinimage(photo.persons)} ${dk_tagslist(photo.keywords)} ${adobe_createdate(photo.date)} ${adobe_modifydate(photo.date)} ${xmp_rating("5" if photo.favorite else None)} ${gps_info(*photo.location)} ${mwg_face_regions(photo)} ${mpri_face_regions(photo)}