Thumbnail image quality

We have some assets in shotgun that are being queried and displayed in a pyside gui. I was wondering if there is a way to query a higher quality thumbnail from the sg field ‘image’ It appears to be a very small compressed image. Are there other versions of the thumbnail I can query or is there a way i can query the original thumbnail (most ideal). That would be most ideal.

filters = []
fields = ['code', 'image', 'sg_type', 'sg_json', 'sg_video']
result = sg.find('CustomNonProjectEntity08', filters, fields)
2 Likes

Yes, and no. It all depends how the thumbnail originated. If you upload a high res image directly to the thumbnail field, then you can access it directly using this URL format:

sg.download_attachment({'url':'https://<site>.shotgunstudio.com/thumbnail/full/<entity_type>/<entity_id>'})

Note, you need to be authenticated for that URL to resolve. If, however, the thumbnail was automatically generated (think the thumbnail field on a Version), then it will just have the lower res output that was created as part of the transcoding process.

1 Like

What do you mean i need to be authenticated? When i call

sg.download_attachment("https://<site>.shotgunstudio.com/thumbnail/full/CustomNonProjectEntity08/39")

i get the following error:

    Traceback (most recent call last):
      File "C:\Users\jmartini\Desktop\Trash\hunterVideos\queryAssets.py", line 19, in <module>
        print sg.download_attachment(url)
      File "C:\Python27\lib\site-packages\shotgun_api3\shotgun.py", line 2491, in download_attachment
        url = self.get_attachment_download_url(attachment)
      File "C:\Python27\lib\site-packages\shotgun_api3\shotgun.py", line 2600, in get_attachment_download_url
        "dict, int, or NoneType. Instead got %s" % type(attachment))
    TypeError: Unable to determine download url. Expected dict, int, or NoneType. Instead got <type 'str'>

However if i directly go to that url the image displays in the browser. Why would that be?

1 Like

That’s what I get for copy/pasting code before :coffee:. I fixed the snippet in the above example, give that a try.

1 Like

Hey Brandon,
I was looking at using what you suggested but it appears to return a unusable result. My goal was to get the full url path to the original uploaded image. I’m not quite sure what it is returning at the moment, however it doesn’t appear to be the url to the image. Is there a way to do that?

Below is my updated snippet. You’ll notice it opens the low res thumbnail in the browser. My goal is to have it open the original raw one in the browser as well, or at least return the url for it more importantly.

def getFullRawThumbnail():
    entityType = 'CustomNonProjectEntity08'
    entityID = 423
    filters = [['id', 'is', entityID]]
    fields = ['code', 'image', 'sg_type']
    result = sg.find_one(entityType, filters, fields)
    os.startfile(result['image'])

    result = sg.download_attachment({'url':'https://******.shotgunstudio.com/thumbnail/full/{}/{}'.format(entityType, entityID)})
    print result
    os.startfile(result)

if __name__ == '__main__':
    getFullRawThumbnail()
1 Like

What sort of result are you getting? If you’re not supplying a file_path as part of the download_attachment() call, then it’s returning the actual data of the file itself.

https://developer.shotgunsoftware.com/python-api/reference.html#shotgun_api3.shotgun.Shotgun.download_attachment

I’m not sure how os.startfile() interacts with a raw file stream. If you first save the file locally and then try to open it, how does that work for you?

1 Like

I found the solution last night :slight_smile:

def getFullRawThumbnail():
    entityType = 'CustomNonProjectEntity08'
    entityID = 423
    filters = [['id', 'is', entityID]]
    fields = ['code', 'image', 'sg_type']
    lowFile = sg.find_one('CustomNonProjectEntity08', filters, fields)
    os.startfile(lowFile['image'])

    # result = sg.download_attachment({'url':'https://***.shotgunstudio.com/thumbnail/full/{}/{}'.format(entityType, entityID)})
    rawFile = sg.get_attachment_download_url({'url':'https://***.shotgunstudio.com/thumbnail/full/{}/{}'.format(entityType, entityID)})
    os.startfile(rawFile)
    print rawFile
3 Likes

I know this is an old thread, this is still an issue for me. There seems to be discrepancies between the Shotgun site, the REST API, and the Python API in regards to thumbnails.

I’m simply trying to download thumbnails for any given entity. On the Shotgrid site, Versions have their own thumbnails which are automatically generated from uploaded .mov files. Shots have thumbnails displayed based on a query (generally most recent Version).

When downloading Version thumbnails, I get the following results:

  • Python API, reading the Version entity[‘image’] field:
    A signed s3 link to the low-res thumbnail (480x270)

  • Shotgun HTTP site, using https://{site}/thumbnail/Version/{id}/
    Redirect to s3 link for the low-res thumbnail (480x270)

  • Shotgun HTTP site, using https://{site}/thumbnail/full/Version/{id}/
    Redirect to s3 link for a full res thumbnail at the original .mov resolution

  • Shotgun REST API, using /api/v1/entity/Version/{id}/image?alt={size}
    Low-res if size=“thumbnail”, full-res if size=“original”

However, when downloading Shot thumbnails

  • Python API, reading the Shot entity[‘image’] field:
    A signed s3 link to the low-res Version thumbnail (480x270)

  • Shotgun HTTP site, using https://{site}/thumbnail/Shot/{id}/
    404 not found

  • Shotgun HTTP site, using https://{site}/thumbnail/full/Shot/{id}/
    404 not found

  • Shotgun REST API, using /api/v1/entity/Version/{id}/image?alt={size}
    404 not found for either original or thumbnail size

So it seems using the Python API actually follows the Shot thumbnail query and returns the correct thumbnail link, but only at low res (480x270). The REST API does not and returns 404.

But what I really need is a way to get the queried thumbnail for a shot at full res.

Is there any way to do this using any of the APIs?

For anyone else with the same issues, turns out there’s an “image_source_entity” field that is exactly what I needed. It’s accessible as an entity field via the Python api or as a relationships/image_source_entity object from the REST API and it returns the thumbnail source entity for any other given entity.

Then you can grab the full res thumbnail for the image_source_entity via the REST API or directly via http.

Note the image_source_entity field doesn’t seem to be mentioned in either the python or REST api documentation, though I did find a brief explanation of it here.