2013-01-01 17 views

Odpowiedz

8

nazwa pliku miniatury to md5 nazwy pliku. Jednak nazwa pliku jest bezwzględnym identyfikatorem URI obrazu (bez nowej linii).

Więc trzeba zrobić:

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

A jeśli zawiera spacje, należy przekonwertować je na '20%', ex "tratata bar.jpg"

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

Znaleziono na Ubuntu forums. Zobacz także dokument Thumbnail Managing Standard, połączony z freedesktop.org wiki.

+0

Kiedy nie ma miniatury, jaki jest mechanizm wymuszający generowanie? –

0

Domyślam się, że chcesz uzyskać dostęp do miniatury programowo. Chcesz użyć Gio library.

Nie znalazłem sposobu na sprawdzenie miniatury, a jeśli nie istnieje, przejdź do ikony aplikacji, więc musisz zrobić to w dwóch krokach. Tutaj masz próbkę (przepraszam, Python, nie jestem biegły w C):

import gio 
import gtk 

window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
window.show() 
hbox = gtk.HBox() 
hbox.show() 
window.add(hbox) 

f = gio.File(path='/home/whatever/you/want.jpg') 
info = f.query_info('*') 

# We check if there's a thumbnail for our file 
preview = info.get_attribute_byte_string ("thumbnail::path") 

image = None 
if preview: 
    image = gtk.image_new_from_file (preview) 
else: 
    # If there's no thumbnail, we check get_icon, who checks the 
    # file's mimetype, and returns the correct stock icon. 
    icon = info.get_icon() 
    image = gtk.image_new_from_gicon (icon, gtk.ICON_SIZE_MENU) 

hbox.add (image) 

window.show_all() 
gtk.main() 
2

Proste narzędzie Pythona do obliczania ścieżki miniatury. Napisane przez Raja, udostępnione jako ActiveState code recipe. Należy jednak zauważyć, że ten kod nie zawiera nazw plików ze spacjami lub znakami specjalnymi; co oznacza, że ​​ten kod nie działa dla wszystkich nazw plików.

"""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') 
Powiązane problemy