I am trying to export rasters stored in a raster field in a gdb feature class to thumbnail-sized jpg with arcpy. The reason is so that I can attach them to the feature class to be displayed in a popup in ArcGIS online.
If I click on the raster field in ArcMap, the thumbnails are shown, but I am not sure how to export them with arcpy.
I have considered copying the raster to jpg, but what I really want is a down-sampled jpg (ideally less than 1mb each). I could use ExportToJPG, but then I would need to set up an mxd.
The @FelixIP suggestion to resample works well to create thumbnails. Here is a functional snipped to create thumbnails, and add the URL and thumbnail name to a table that could be used to show the thumbnail in AGOL.
#Export Raster to Thumbnail Tif
import os
import arcpy
from arcpy import env
rcat = "location of an unmanaged raster catalog"
pathsName = "name of output location of a table of raster paths"
#Export raster catalog paths to dbf table
arcpy.ExportRasterCatalogPaths_management(rCat, "ALL", pathsName)
# Add fields to store some useful fields to help manage thumbnail paths
arcpy.AddField_management(pathsName, "thumbURL", "TEXT", field_length=500)
arcpy.AddField_management(pathsName, "rasName", "TEXT", field_length=100)
#Use data access cursor to loop through table and create thumbnails
with arcpy.da.UpdateCursor(pathsName, seColumns) as cursor:
for row in cursor:
#Assign the raster path to a variable from the table
rasPath = str(row[1])
#assign input raster name to a variable
inName = arcpy.Describe(rasPath).name
#Create a URL for the thumbnail to be stored later
tURL = "web server location" + inName + ".png"
#Write thumbnail URL and raster name
row[2] = tURL
row[3] = inName
#update the rows
cursor.updateRow(row)
#Create thumbnail to send to web
outThumbLoc = 'tumbnail storage folder'
#Create thumbnail name
outThumb = os.path.join(outThumbLoc, inName + ".png")
#Use resample to create thumbnails
try:
arcpy.Resample_management(rasPath, outThumb, tScale, "BILINEAR")
except Exception as err:
print rasPath
print(err.args[0])