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