2012-02-08 31 views

回答

5

我找到了一個解決方案,我寫了一個函數來完成這項工作

#!/usr/bin/env python 
import gio, gtk, os 

    def get_icon_filename(filename,size): 
     #final_filename = "default_icon.png" 
     final_filename = "" 
     if os.path.isfile(filename): 
      # Get the icon name 
      file = gio.File(filename) 
      file_info = file.query_info('standard::icon') 
      file_icon = file_info.get_icon().get_names()[0] 
      # Get the icon file path 
      icon_theme = gtk.icon_theme_get_default() 
      icon_filename = icon_theme.lookup_icon(file_icon, size, 0) 
      if icon_filename != None: 
       final_filename = icon_filename.get_filename() 

     return final_filename 


    print get_icon_filename("/home/el7r/Music/test.mp3",64) 

感謝所有

-2

ImageMagick非常適合從命令行進行基本操作。在http://www.imagemagick.org/script/index.php

+0

看來,這個包只讓縮圖,和編輯圖像,可以將它生成縮略圖,或者圖標MPG,OGG,MP3,ZIP,焦油。 gz? – 2012-02-08 23:57:32

2

我不認爲圖標文件是相同的跨平臺資料...

在Mac上,圖標都存儲在應用程序包 - EG:

/Applications/Mail.app/Contents/Resources/app.icns 

在Linux的他們似乎是相似的,但不同的地方。例如:

/usr/lib/firefox/icons/mozicon16.xpm 

所以,我覺得你的運氣了一個簡單的,跨平臺的解決方案,將有來編碼routin E要考慮適當的地方爲每個操作系統

2

感謝@Ali_AlNoaimi他的解決方案。我改成了與python3和PyGI工作:

import os , gi 
gi.require_version('Gtk', '3.0') 
from gi.repository import Gio , Gtk 


def get_thumbnail(filename,size): 
    final_filename = "" 
    if os.path.exists(filename): 
     file = Gio.File.new_for_path(filename) 
     info = file.query_info('standard::icon' , 0 , Gio.Cancellable()) 
     icon = info.get_icon().get_names()[0] 

     icon_theme = Gtk.IconTheme.get_default() 
     icon_file = icon_theme.lookup_icon(icon , size , 0) 
     if icon_file != None: 
      final_filename = icon_file.get_filename() 
     return final_filename 

print(get_thumbnail("/path/to/file",32))