问题:
Ubuntu的文件管理器Nautilus广泛支持文件预览。这些缩略图由称为缩略图的帮助程序处理。
随Ubuntu预装的缩略图的数量是有限的,因此默认情况下不会渲染一些其他奇特的文件类型。
在这些情况下,我可以安装哪些其他缩略图来激活预览?
相关问答:
注意事项:
随时通过编辑社区Wiki答案为该列表做出贡献。如果这样做,请遵循本元讨论中的准则,并使用预先存在的模式来保持答案的一致性。
问题:
Ubuntu的文件管理器Nautilus广泛支持文件预览。这些缩略图由称为缩略图的帮助程序处理。
随Ubuntu预装的缩略图的数量是有限的,因此默认情况下不会渲染一些其他奇特的文件类型。
在这些情况下,我可以安装哪些其他缩略图来激活预览?
相关问答:
注意事项:
随时通过编辑社区Wiki答案为该列表做出贡献。如果这样做,请遵循本元讨论中的准则,并使用预先存在的模式来保持答案的一致性。
Answers:
存储库和PPA中的缩略图
许多缩略图已预先打包,可以从软件中心或命令行轻松安装。这些缩略图不需要任何其他配置,并且在重新启动Nautilus之后应该可以正常工作。您可以这样做:
nautilus -q 
在从PPA安装任何内容之前,请考虑阅读以下问答:
PPA可以安全地添加到我的系统中,需要注意哪些“危险信号”?
在Ubuntu 11.04及更高版本上的自定义缩略图脚本
存储库中不可用的自定义缩略图必须手动安装。这些是您必须安装的步骤:
检查该脚本是否列出了任何依赖项。如果是这样,请先安装它们。
下载脚本并使其可通过Nautiluschmod a+x filethumbnailer或通过Nautilus执行
在文件系统中为以后的所有缩略图指定一个文件夹,并将脚本移至该文件夹,例如
mkdir $HOME/.scripts/thumbnailers && mv filethumbnailer $HOME/.scripts/thumbnailers
接下来,您将必须向Nautilus注册脚本。为此,请在中创建一个缩略图条目/usr/share/thumbnailers。该条目应遵循命名方案foo.thumbnailer,其中foo是您选择的表达式(在此处file):
gksudo gedit /usr/share/thumbnailers/file.thumbnailer
缩略图规范遵循以下方案:
[Thumbnailer Entry]
Exec=$HOME/.scripts/thumbnailers/file.thumbnailer %i %o %s
MimeType=application/file;
该Exec条目指向您的缩略图脚本,而该MimeType字段指定了相关的MimeType。可能的变量是:
%i Input file path
%u Input file URI
%o Output file path
%s Thumbnail size (vertical)
每个脚本的规格和变量将有所不同。只需将相应文本框的内容复制并粘贴到文件中并保存。
重新启动nautilus(nautilus -q)后,缩略图应已启动并正在运行。
在Ubuntu 11.04及更低版本上的自定义缩略图脚本
Ubuntu的早期版本依赖GConf进行缩略图关联。有关更多信息,请参见此处。
资料来源:
https://live.gnome.org/ThumbnailerSpec
https://bugzilla.redhat.com/show_bug.cgi?id=636819#c29
https://bugs.launchpad.net/ubuntu/+source/gnome-exe-thumbnailer/+bug/752578
http://ubuntuforums.org/showthread.php?t=1881360
CHM文件
总览
描述:使用此脚本,您将在nautilus文件管理器中获取chm文件的缩略图。该脚本使用chm文件首页中最大的图像来生成缩略图,通常这是封面的图像。
创建者:monraaf(http://ubuntuforums.org/showthread.php?t=1159569)
依存关系:
sudo apt-get install python-beautifulsoup python-chm imagemagick
缩略图输入
[Thumbnailer Entry]
Exec=$HOME/.scripts/thumbnailers/chmthumbnailer %i %o %s
MimeType=application/vnd.ms-htmlhelp;application/x-chm;
脚本
#!/usr/bin/env python
import sys, os
from chm import chm
from BeautifulSoup import BeautifulSoup
class ChmThumbNailer(object):
    def __init__(self):
        self.chm = chm.CHMFile()
    def thumbnail(self, ifile, ofile, sz):
        if self.chm.LoadCHM(ifile) == 0:
            return 1
        bestname    = None
        bestsize    = 0
        base        = self.chm.home.rpartition('/')[0] + '/'
        size, data  = self.getfile(self.chm.home)
        if size > 0:
            if self.chm.home.endswith(('jpg','gif','bmp')):
                self.write(ofile, sz, data)
            else:
                soup = BeautifulSoup(data)
                imgs = soup.findAll('img')
                for img in imgs:
                    name = base + img.get("src","")
                    size, data = self.getfile(name)
                    if size > bestsize:
                        bestsize = size
                        bestname = name
                if bestname != None:
                    size, data = self.getfile(bestname)
                    if size > 0:
                        self.write(ofile, sz, data)
        self.chm.CloseCHM()
    def write(self, ofile, sz, data):
        fd = os.popen('convert - -resize %sx%s "%s"' % (sz, sz, ofile), "w")
        fd.write(data)
        fd.close()
    def getfile(self,name):
        (ret, ui) = self.chm.ResolveObject(name)
        if ret == 1:
            return (0, '')
        return self.chm.RetrieveObject(ui)
if len(sys.argv) > 3:
    chm = ChmThumbNailer()
    chm.thumbnail(sys.argv[1], sys.argv[2], sys.argv[3])
EPUB文件
总览
描述:epub-thumbnailer是一个简单的脚本,试图在epub文件中查找封面并为其创建缩略图。
创建者:Mariano Simone(https://github.com/marianosimone/epub-thumbnailer)
依赖关系:未列出,可以立即正常工作
缩略图输入
[Thumbnailer Entry]
Exec=$HOME/.scripts/thumbnailers/epubthumbnailer %i %o %s
MimeType=application/epub+zip;
脚本
#!/usr/bin/python
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
# Author: Mariano Simone (marianosimone@gmail.com)
# Version: 1.0
# Name: epub-thumbnailer
# Description: An implementation of a cover thumbnailer for epub files
# Installation: see README
import zipfile
import sys
import Image
import os
import re
from xml.dom import minidom
from StringIO import StringIO
def get_cover_from_manifest(epub):
    img_ext_regex = re.compile("^.*\.(jpg|jpeg|png)$")
    # open the main container
    container = epub.open("META-INF/container.xml")
    container_root = minidom.parseString(container.read())
    # locate the rootfile
    elem = container_root.getElementsByTagName("rootfile")[0]
    rootfile_path = elem.getAttribute("full-path")
    # open the rootfile
    rootfile = epub.open(rootfile_path)
    rootfile_root = minidom.parseString(rootfile.read())
    # find the manifest element
    manifest = rootfile_root.getElementsByTagName("manifest")[0]
    for item in manifest.getElementsByTagName("item"):
        item_id = item.getAttribute("id")
        item_href = item.getAttribute("href")
        if "cover" in item_id and img_ext_regex.match(item_href.lower()):
            cover_path = os.path.join(os.path.dirname(rootfile_path), 
                                      item_href)
            return cover_path
    return None
def get_cover_by_filename(epub):
    cover_regex = re.compile(".*cover.*\.(jpg|jpeg|png)")
    for fileinfo in epub.filelist:
        if cover_regex.match(os.path.basename(fileinfo.filename).lower()):
            return fileinfo.filename
    return None
def extract_cover(cover_path):
    if cover_path:
        cover = epub.open(cover_path)
        im = Image.open(StringIO(cover.read()))
        im.thumbnail((size, size), Image.ANTIALIAS)
        im.save(output_file, "PNG")
        return True
    return False
# Which file are we working with?
input_file = sys.argv[1]
# Where do does the file have to be saved?
output_file = sys.argv[2]
# Required size?
size = int(sys.argv[3])
# An epub is just a zip
epub = zipfile.ZipFile(input_file, "r")
extraction_strategies = [get_cover_from_manifest, get_cover_by_filename]
for strategy in extraction_strategies:
    try:
        cover_path = strategy(epub)
        if extract_cover(cover_path):
            exit(0)
    except Exception as ex:
        print "Error getting cover using %s: " % strategy.__name__, ex
exit(1)
EXE文件
总览
Description(说明):gnome-exe-thumbnailer是Gnome的缩略图,它将为Windows .exe文件提供一个图标,该图标基于其嵌入式图标和通用的“ Wine程序”图标。如果程序具有正常的执行权限,则将显示标准的嵌入式图标。该缩略图器还将为.jar,.py和类似的可执行程序提供缩略图图标。
可用性:官方资料库
安装
sudo apt-get install gnome-exe-thumbnailer
ODP / ODS / ODT和其他LibreOffice和Open Office文件
总览
说明: ooo-thumbnailer是LibreOffice,OpenOffice.org和Microsoft Office文档缩略图,Nautilus可以使用它为您的文档,电子表格,演示文稿和工程图创建缩略图。
可用性:开发人员的PPA(与Ubuntu 12.04及更高版本中的LibreOffice兼容的最新版本)
安装
sudo add-apt-repository ppa:flimm/ooo-thumbnailer && apt-get update && apt-get install ooo-thumbnailer
              /* XPM */标头之前带有注释的文件,即使eog它们显示得很好
                    file -i FILE
                    ICNS文件(Mac OSX图标)
总览
由于某些错误,Nautilus不会为Mac OSX图标生成缩略图,但内置了支持GdkPixbuf。
脚本
这是生成.icns文件缩略图的基本脚本。可以在https://github.com/MestreLion/icns-thumbnailer中找到更强大的版本
#!/usr/bin/env python
import sys
from gi.repository import GdkPixbuf
inputname, outputname, size = sys.argv[1:]
pixbuf = GdkPixbuf.Pixbuf.new_from_file(inputname)
scaled = GdkPixbuf.Pixbuf.scale_simple(pixbuf, int(size), int(size),
                                       GdkPixbuf.InterpType.BILINEAR)
scaled.savev(outputname, 'png', [], [])
安装
icns-thumbnailer项目存储库.thumbnailer中提供了安装脚本以及Nautilus文件。
.xpm的图像?我以为他们是“标准”的png,jpg和bmp,但鹦鹉螺不会生成预览他们。