Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the thumbnail that nautilus uses for a given file?

Nautilus shows me a thumbnail of a file, if its an image it will show me a preview, if its a video it will show a frame from the video, if its a document it will show me the application icon.

How can I access the image?

I see they are cached in ~/.thumbnail/ however they are all given unique names.

like image 273
Phil Hannent Avatar asked Jan 01 '13 17:01

Phil Hannent


People also ask

Where are Nautilus thumbnails?

There is a hidden directory in your home called . thumbnails. If you delete a file (or all) there, its thumbnail will be recreated by nautilus the next time that you visit the dir where it's stored.

How do I view a thumbnail file?

In the search box, type File Explorer Options. Select File Explorer Options from the menu. In the File Explorer Options window, click on the View tab. Uncheck Always show icons, never thumbnails option.

What is a thumbnail of a file?

A miniature representation of a page or image that is used to identify a file by its contents. Clicking the thumbnail opens the file. Thumbnails are an option in file managers, such as Windows Explorer, and they are found in photo editing and graphics programs to quickly browse multiple images in a folder.

Where does ubuntu store thumbnails?

For each displayed picture, Ubuntu automatically creates a thumbnail, for viewing in the file manager. It stores those thumbnails in a hidden directory in your user account (names of hidden directories and hidden files start with a dot, like . cache or . bash_history.


2 Answers

the thumbnail filename is an md5 of the filename. However the filename is the absolute URI to the image (without a newline).

So you need to do:

echo -n 'file:///home/yuzem/pics/foo.jpg' | md5sum

And if it has spaces, you need to convert them to '%20', ex for "foo bar.jpg"

echo -n 'file:///home/yuzem/pics/foo%20bar.jpg' | md5sum

Found at Ubuntu forums. See also the Thumbnail Managing Standard document, linked from the freedesktop.org wiki.

like image 182
zed_0xff Avatar answered Oct 09 '22 05:10

zed_0xff


Simple Python tool to calculate the thumbnail path. Written by Raja, shared as an ActiveState code recipe. Note, however, that this code does not escape filenames with spaces or special characters; which means this code does not work for all filenames.

"""Get the thumbnail stored on the system.
Should work on any linux system following the desktop standards"""

import hashlib
import os

def get_thumbnailfile(filename):
    """Given the filename for an image, return the path to the thumbnail file.
    Returns None if there is no thumbnail file.
    """
    # Generate the md5 hash of the file uri
    file_hash = hashlib.md5('file://'+filename).hexdigest()

    # the thumbnail file is stored in the ~/.thumbnails/normal folder
    # it is a png file and name is the md5 hash calculated earlier
    tb_filename = os.path.join(os.path.expanduser('~/.thumbnails/normal'),
                               file_hash) + '.png'

    if os.path.exists(tb_filename):
        return tb_filename
    else:
        return None

if __name__ == '__main__':
    import sys
    if len(sys.argv) < 2:
        print('Usage:  get_thumbnail.py filename')
        sys.exit(0)

    filename = sys.argv[1]
    tb_filename = get_thumbnailfile(filename)

    if tb_filename:
        print('Thumbnail for file %s is located at %s' %(filename, tb_filename))
    else:
        print('No thumbnail found')
like image 38
Denilson Sá Maia Avatar answered Oct 09 '22 03:10

Denilson Sá Maia