Is there a method that will allow one to reduce the size (ie photo resolution) of fgdb record attachments, while they are still attached to the records inside the fgdb (as opposed to downloading the files and resizing outside of the fgdb)?
Hi there,
I know it's an old thread but in case someone stumbles upon this issue I managed to compress them with this snippet
# Tested in ArcGIS PRO 3.5.x import arcpy import os import tempfile from PIL import Image import io # Attachment table in_table = "" quality = 70 with tempfile.TemporaryDirectory() as tmpdirname: with arcpy.da.UpdateCursor(in_table, ['DATA', 'ATT_NAME', 'DATA_SIZE']) as cursor: for row in cursor: attachment = row[0] filename = row[1] exported_img = os.path.join(tmpdirname, filename) open(exported_img, 'wb').write(attachment.tobytes()) image = Image.open(exported_img) stream = io.BytesIO() image.save(stream, format='JPEG', quality=quality, exif=image.info.get("exif")) imagebytes = stream.getvalue() row[0] = imagebytes row[2] = len(imagebytes) cursor.updateRow(row)
It was tested on one of the two identical FileGDBs, which is actually compressing them based on the output:
Funny thing, the FileGDB size itself does not seem to shrink by itself, it's like it maintains the allocated storage. But that's for another day...
Hope this helps!
Thanks. I think you are right on all fronts, especially the ton of work part.
If the attachments are stored in a BLOB field, which I think they would be, I do not think you can make changes to the attachments. I think you would need to write the attachments out to a different format, make the resolution changes, and then save back in BLOB format. Seems like a ton of work.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.