<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to rename attachment based on field name? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-rename-attachment-based-on-field-name/m-p/1535857#M10632</link>
    <description>&lt;P&gt;Moving to ArcGIS API for Python questions &lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/bd-p/arcgis-api-for-python-questions" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-python-questions/bd-p/arcgis-api-for-python-questions&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2024 09:52:53 GMT</pubDate>
    <dc:creator>NicholasGiner1</dc:creator>
    <dc:date>2024-09-06T09:52:53Z</dc:date>
    <item>
      <title>How to rename attachment based on field name?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-rename-attachment-based-on-field-name/m-p/1511474#M10631</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi, everyone. I am new to using ArcGIS Notebook and I would like to automate the workflow for my fieldwork operations. Specifically, I would like to have the workers take photos using ArcGIS Fieldmaps, and then use ArcGIS Notebook to insert a date watermark into those photos. Finally, I would like to zip the photos into a file. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The part I'm stuck on is renaming the photo attachments. I would like to rename them based on a field name, such as "TreeID". Could you please provide some guidance on how I can accomplish this workflow in an efficient manner? I'm happy to provide any additional details that might be helpful. Thank you in advance for your assistance.&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;import datetime&lt;BR /&gt;import os&lt;BR /&gt;import zipfile&lt;BR /&gt;from arcgis.gis import GIS&lt;BR /&gt;from PIL import Image&lt;BR /&gt;from PIL import ExifTags&lt;BR /&gt;from PIL import ImageDraw, ImageFont&lt;BR /&gt;from PIL.ExifTags import GPSTAGS, TAGS&lt;/P&gt;&lt;P&gt;'''&lt;BR /&gt;&lt;A href="https://github.com/Esri/field-maps-scripts/blob/main/notebooks/Generate%20PDF%20Report/Generate%20PDF%20Report.ipynb" target="_blank"&gt;https://github.com/Esri/field-maps-scripts/blob/main/notebooks/Generate%20PDF%20Report/Generate%20PDF%20Report.ipynb&lt;/A&gt;&lt;BR /&gt;'''&lt;BR /&gt;def format_datetime(original_datetime):&lt;BR /&gt;# Split the original datetime into date and time components&lt;BR /&gt;date, time = original_datetime.split()&lt;/P&gt;&lt;P&gt;# Change the date format from yyyy:mm:dd to yyyy-mm-dd&lt;BR /&gt;formatted_date = date.replace(':', '-')&lt;/P&gt;&lt;P&gt;return f"{formatted_date}\n{time}"&lt;/P&gt;&lt;P&gt;def add_date_watermark(image_path):&lt;BR /&gt;image = Image.open(image_path)&lt;BR /&gt;exif = image.getexif()&lt;BR /&gt;watermark_text = None&lt;/P&gt;&lt;P&gt;gps_info = {}&lt;BR /&gt;draw = ImageDraw.Draw(image)&lt;BR /&gt;watermark_text = exif[306]&lt;BR /&gt;print ("success")&lt;BR /&gt;&lt;BR /&gt;if hasattr(image, '_getexif'):&lt;BR /&gt;exif = image._getexif()&lt;BR /&gt;if exif is not None:&lt;BR /&gt;orientation = exif.get(274, 1) # Get the orientation tag, default to 1 if missing&lt;BR /&gt;rotations = {&lt;BR /&gt;3: Image.ROTATE_180,&lt;BR /&gt;6: Image.ROTATE_270,&lt;BR /&gt;8: Image.ROTATE_90&lt;BR /&gt;}&lt;BR /&gt;if orientation in rotations:&lt;BR /&gt;image = image.transpose(rotations[orientation])&lt;/P&gt;&lt;P&gt;print ("watermark")&lt;BR /&gt;print (watermark_text)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# Get the original datetime from EXIF&lt;BR /&gt;original_datetime = exif.get(306, "No date found")&lt;BR /&gt;&lt;BR /&gt;# Format the datetime as per the new requirement&lt;BR /&gt;formatted_datetime = format_datetime(original_datetime)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;draw = ImageDraw.Draw(image)&lt;BR /&gt;&lt;BR /&gt;# Specify the font size and use a system font directly&lt;BR /&gt;font = ImageFont.load_default()&lt;BR /&gt;&lt;BR /&gt;# Increase the font size&lt;BR /&gt;font = font.font_variant(size=36)&lt;BR /&gt;&lt;BR /&gt;# Create the updated watermark text with formatted datetime&lt;BR /&gt;updated_watermark_text = f"{formatted_datetime}"&lt;BR /&gt;&lt;BR /&gt;draw.text((720, 1150), updated_watermark_text, fill=(255, 104, 32), font=font)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;# Save the processed image to a temporary directory&lt;BR /&gt;save_path = r'/arcgis/home/watermark2/' + os.path.basename(image_path)&lt;BR /&gt;image.save(save_path)&lt;BR /&gt;&lt;BR /&gt;return save_path&lt;/P&gt;&lt;P&gt;# Process images and save them to a zip file&lt;BR /&gt;processed_images = []&lt;BR /&gt;gis = GIS('home')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;layer_item_id = "86fxxxxxxxxxxxxxxxxx469bbb08"&lt;BR /&gt;layer_item = gis.content.get(layer_item_id)&lt;BR /&gt;layer = layer_item.layers[0]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;attachments_list = layer.attachments.search(attachment_types=['image/jpeg'])&lt;BR /&gt;oid_list = layer.query(attachment_types=['image/jpeg'], return_ids_only=True)['objectIds']&lt;BR /&gt;attachments = layer.attachments.download(oid=oid_list, save_path=r'/arcgis/home/watermark2/')&lt;/P&gt;&lt;P&gt;for attach in attachments:&lt;BR /&gt;processed_image_path = add_date_watermark(attach)&lt;BR /&gt;processed_images.append(processed_image_path)&lt;BR /&gt;&lt;BR /&gt;# Create a zip file containing all processed images&lt;BR /&gt;zip_filename = r'/arcgis/home/watermark2/processed_images.zip'&lt;BR /&gt;with zipfile.ZipFile(zip_filename, 'w') as zipf:&lt;BR /&gt;for img in processed_images:&lt;BR /&gt;zipf.write(img, os.path.basename(img))&lt;/P&gt;&lt;P&gt;print("Images processed and saved as a zip file.")&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 29 Jul 2024 08:59:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-rename-attachment-based-on-field-name/m-p/1511474#M10631</guid>
      <dc:creator>RikiChan</dc:creator>
      <dc:date>2024-07-29T08:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename attachment based on field name?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-rename-attachment-based-on-field-name/m-p/1535857#M10632</link>
      <description>&lt;P&gt;Moving to ArcGIS API for Python questions &lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/bd-p/arcgis-api-for-python-questions" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-python-questions/bd-p/arcgis-api-for-python-questions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 09:52:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-rename-attachment-based-on-field-name/m-p/1535857#M10632</guid>
      <dc:creator>NicholasGiner1</dc:creator>
      <dc:date>2024-09-06T09:52:53Z</dc:date>
    </item>
  </channel>
</rss>

