<?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: Create Watermark on images post processing in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/create-watermark-on-images-post-processing/m-p/1248062#M6231</link>
    <description>&lt;P&gt;On first glance, it looks like you're trying to reference a layer, which PIL wouldn't know how to open. In the block "In [6]", you can see how it loops through the attachments downloads the image to a local directory. Once you have the JPEG locally, Image.open can read the data.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jan 2023 15:16:53 GMT</pubDate>
    <dc:creator>IanTodd</dc:creator>
    <dc:date>2023-01-13T15:16:53Z</dc:date>
    <item>
      <title>Create Watermark on images post processing</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/create-watermark-on-images-post-processing/m-p/1248049#M6230</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to follow this example that seems to show how to post process images in a Feature Class with a watermark.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/field-maps-scripts/blob/master/notebooks/Generate%20PDF%20Report/Generate%20PDF%20Report.ipynb" target="_blank" rel="noopener"&gt;https://github.com/Esri/field-maps-scripts/blob/master/notebooks/Generate%20PDF%20Report/Generate%20PDF%20Report.ipynb&lt;/A&gt;&lt;/P&gt;&lt;P&gt;As you can see from the code below I have commented out a bunch in the process_image function.&lt;/P&gt;&lt;P&gt;I am first off trying to get the&amp;nbsp; Lat Long and Time from the image and simply print those out ...&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I cannot figure out what the input_file parameter needs to be set to... As you can see I am trying to use the variable that was set earlier&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I am not seeing where the script reads all the records and checks all the images that may exist on a single feature in the dataset.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
from arcgis.gis import GIS
from PIL import Image, ImageOps, ImageDraw, ImageFont
import base64
import io
import json
import datetime
from PIL.ExifTags import GPSTAGS, TAGS

agol_username = 'username' 
agol_password = 'xxxxxx'  
gis = GIS('https://xxxx.maps.arcgis.com', agol_username, agol_password)
item = gis.content.get("eed50dc6xxxxxxxx876021a84eef")
processing_layer = item.layers[0]

def process_image():
    #image = Image.open(input_file)    
    image = Image.open(processing_layer )
    image = ImageOps.exif_transpose(image)
    lat, long, gps_time = get_location_data(image.getexif())
    print(lat)
    print(long)
    print(gps_time)
    
    #image_editable = ImageDraw.Draw(image)
    #font = ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf", 24)
    #image_editable.text((1,1), f'{lat}, {long} at {gps_time.strftime("%Y-%m-%d %H:%M:%S")}', (255,255,0), font=font)
    #io_bytes = io.BytesIO()
    #image.save(io_bytes, format="JPEG")
    #io_bytes.seek(0)
    #return base64.b64encode(io_bytes.read()).decode()

def get_location_data(exif_data):
    exif = { TAGS[k]: v for k, v in exif_data.items() if k in TAGS and type(v) is not bytes }
    lat = None
    long = None
    gps_time = None
    if "GPSInfo" in exif:
        gps_info = {}
        for key, val in GPSTAGS.items():
            if key in exif["GPSInfo"]:
                gps_info[val] = exif["GPSInfo"][key]
        if "GPSLatitude" in gps_info:
            lat = get_decimal_from_dms(gps_info["GPSLatitude"], gps_info["GPSLatitudeRef"])
        if "GPSLongitude" in gps_info:
            long = get_decimal_from_dms(gps_info["GPSLongitude"], gps_info["GPSLongitudeRef"])
        if "GPSDateStamp" in gps_info and "GPSTimeStamp" in gps_info:
            gps_time = datetime.datetime.strptime(gps_info['GPSDateStamp'], '%Y:%m:%d').replace(
                hour=int(gps_info['GPSTimeStamp'][0]),
                minute=int(gps_info['GPSTimeStamp'][1]),
                second=int(gps_info['GPSTimeStamp'][2])
            )
    return (lat, long, gps_time)

def get_decimal_from_dms(dms, ref):
    degrees = float(dms[0])
    minutes = float(dms[1]) / 60.0
    seconds = float(dms[2]) / 3600.0
    decimal_degrees = round(degrees + minutes + seconds, 6)

    if ref in ['S', 'W']:
        decimal_degrees *= -1
    return decimal_degrees

if __name__ == '__main__':
    process_image()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 14:50:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/create-watermark-on-images-post-processing/m-p/1248049#M6230</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-01-13T14:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create Watermark on images post processing</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/create-watermark-on-images-post-processing/m-p/1248062#M6231</link>
      <description>&lt;P&gt;On first glance, it looks like you're trying to reference a layer, which PIL wouldn't know how to open. In the block "In [6]", you can see how it loops through the attachments downloads the image to a local directory. Once you have the JPEG locally, Image.open can read the data.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 15:16:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/create-watermark-on-images-post-processing/m-p/1248062#M6231</guid>
      <dc:creator>IanTodd</dc:creator>
      <dc:date>2023-01-13T15:16:53Z</dc:date>
    </item>
  </channel>
</rss>

