Select to view content in your preferred language

Create Watermark on images post processing

01-13-2023 06:47 AM
Occasional Contributor III



I am trying to follow this example that seems to show how to post process images in a Feature Class with a watermark.

As you can see from the code below I have commented out a bunch in the process_image function.

I am first off trying to get the  Lat Long and Time from the image and simply print those out ...

  1. 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 
  2. 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.

Any help would be greatly appreciated.


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('', agol_username, agol_password)
item = gis.content.get("eed50dc6xxxxxxxx876021a84eef")
processing_layer = item.layers[0]

def process_image():
    #image =    
    image = )
    image = ImageOps.exif_transpose(image)
    lat, long, gps_time = get_location_data(image.getexif())
    #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(), format="JPEG")
    #return base64.b64encode(

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(
    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__':





0 Kudos
1 Reply
New Contributor II

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, can read the data.