Ubuntu的文件管理器Nautilus具有广泛的文件预览支持。这些缩略图由称为缩略图生成器的辅助程序处理。
预装在Ubuntu上的缩略图生成器数量有限,因此一些更特殊的文件类型默认情况下无法渲染。
我可以安装哪些额外的缩略图生成器来激活这些情况下的预览?
相关问答:
注意:
欢迎通过编辑社区维基答案为此列表做出贡献。如果您这样做,请遵循this Meta discussion中的准则,并使用现有的模式保持答案一致。
相关问答:
注意:
欢迎通过编辑社区维基答案为此列表做出贡献。如果您这样做,请遵循this Meta discussion中的准则,并使用现有的模式保持答案一致。
存储库和PPA中的缩略图生成器
许多缩略图生成器已经预先打包,并可以从软件中心或命令行轻松安装。这些缩略图生成器不需要任何额外的配置,在重新启动nautilus后应该立即生效。您可以通过以下方式进行:
nautilus -q
在安装PPA上的任何东西之前,请考虑阅读以下问答:
在Ubuntu 11.04及以上版本上的自定义缩略图脚本
在存储库中不可用的自定义缩略图程序必须手动安装。以下是您需要执行的步骤:
检查脚本是否列出了任何依赖项。如果有,请先安装它们。
下载脚本并使用chmod 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
字段指定相关的Mime类型。可能的变量有:%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文件
概述
描述:gnome-exe-thumbnailer是Gnome的一个缩略图生成器,它会根据Windows的.exe文件中嵌入的图标和通用的“Wine程序”图标为其提供一个图标。如果该程序具有正常的执行权限,则会显示标准的嵌入图标。此缩略图生成器还会为.jar、.py和类似的可执行程序提供缩略图图标。
可用性:官方软件仓库
安装
sudo apt-get install gnome-exe-thumbnailer
ODP/ODS/ODT和其他LibreOffice和Open Office文件
概述
描述:ooo-thumbnailer是一个可以被Nautilus使用的LibreOffice、OpenOffice.org和Microsoft Office文档缩略图生成器,可用于为您的文档、电子表格、演示文稿和绘图创建缩略图。
可用性:开发者的PPA(与Ubuntu 12.04及更高版本兼容的最新版本)
安装
sudo add-apt-repository ppa:flimm/ooo-thumbnailer && apt-get update && apt-get install ooo-thumbnailer
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', [], [])
.thumbnailer
文件,可以在icns-thumbnailer项目仓库中找到。
.xpm
图片怎么办?我以为它们和png
、jpg
和bmp
一样“标准”,但Nautilus无法为它们生成预览。 - MestreLion/* XPM */
标头之前,即使eog
可以正常显示它们。 - MestreLionfile -i FILE
命令来找到文件的MIME类型。 - Wilf