1

Some background:

We were using Collector on Android to collect data for a layer, and we found out that the pictures that were attached contained no EXIF tags at all, including the orientation tag - meaning some photos show upside down, left side up etc. Now we have to rotate every photo manually to make them appear right side up.

Apparent solution:

In order to do that I thought the following steps will be sufficient:

  1. Extract blob data from the attachments table into .jpg files.
  2. Edit the .jpg files and rotate them.
  3. Extract the data from the .jpg files and update the blob field in the attachments table according to the attachment name field.

I managed to figure out steps 1 and 2, but I wonder how to get step 3 to work?

How do I update specific attachment blob fields, from .jpg files content, according to the attachment name?

Is it possible to do with a cursor?

  • 1
    I use infranview to rotate 100s of collector photos at once. – FelixIP May 25 '16 at 18:56
  • @FelixIP The problem is that some photos need to be rotated one way, some the other and some don't need to be rotated at all. It requires more than just batch rotation. Does it offer a solution for that?For now what we have is a program written in python that runs through all images in a directory and allows a quick rotation based on key presses. Thanks! – user20561 May 25 '16 at 20:06
  • 99% correct output – FelixIP May 25 '16 at 21:15
  • @FelixIP I tried it but I can't find auto rotation functionality. – user20561 May 26 '16 at 7:58
  • No such function. Make batch convert from jpg to jpg – FelixIP May 26 '16 at 8:05
1

Yes you can. You should be able to do this with an update cursor.

Something like this would work:

# make sure you're in an edit session
fields = [blob_field, file_name] #blob field is your blob field and file_name is the file name field
with arcpy.da.UpdateCursor(attachments, fields) as rows:
    for r in rows:
        # save to jpg on disk for temp editing
        jpg = r'C:\some_path_tosave\{}'.format(r[1])
        data = open(jpg, 'wb').write(r[0].tobytes())

        # do your step 1 with data
        # do your step 2 with data
        # do your step 3 with data

        # now you're ready to write it back in
        r[0] = open(jpg, 'rb').read()
        rows.updateRow(r)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.