a customer wants website thumbnail snapshots for his website directory à
la websnapr.com or artviper.net.
Does anybody know of a library (preferably Python) that can generate
such thumbnails under Linux? I guess, one would need to automate FF
somehow to achieve this, but the solutions I've seen so far all seem to
use IE and thus require a windows server.
Would be nice to have an easy-to-use TG widget for this.
Chris
Nadav
I'm not aware of a ready-to-go solution, but at least under Qt you
should be able to utilize the KHTML component to render a bitmap file.
> Would be nice to have an easy-to-use TG widget for this.
This isn't a TG widget domain. A widget is a server-side,
HTML-processing thing. There is no way it can accomplish that.
Diez
>> Does anybody know of a library (preferably Python) that can generate
>> such thumbnails under Linux? I guess, one would need to automate FF
>> somehow to achieve this, but the solutions I've seen so far all
>> seem to
>> use IE and thus require a windows server.
It requires a shell out, but the standard-ish way of doing this is to
call ImageMagick. Give it the right command line args and it'll generate
a thumbnail for you.
Cheers,
Arthur
--
Individuals bearing witness do not change history; only movements
that understand their social world can do that - Ellen Willis
That's a god idea. I will look into that.
>>Would be nice to have an easy-to-use TG widget for this.
>
> This isn't a TG widget domain. A widget is a server-side,
> HTML-processing thing. There is no way it can accomplish that.
I beg to differ (untested, but I do a similar thing with gravatar images):
import md5
from os.path import join
from urllib import quote_plus
import cherrypy
from turbogears import config, controllers
from turbogears import url as tg_url
from turbogears.widgets import *
class Snapshot(Widget):
template = """<img xmlns:py="http://purl.org/kid/ns#" py:attrs="attrs"
src="${url}" />"""
params = ['url', 'size']
url = None
size = 200
_controller_url = '/snapshot'
def update_params(self, params):
"""Converts site URL to URL to our controller.
"""
super(Snapshot, self).update_params(params)
url = "%s?site=%s&size=%i" % (self._controller_url,
quote_plus(params['url']), params['size'])
params['url'] = tg_url(url)
params['attrs'].setdefault('class', 'snapshot')
class SnapshotController(controllers.Controller):
def __init__(self, cache_dir=None):
self.cache_dir = cache_dir
if not cache_dir:
self.cache_dir = join(
config.get('static_filter.dir', path="/static"),
'images', 'snapshots')
@expose()
def default(self, site, size):
"""Get website snapshot from cache or schedule generation."""
# look up and/or generate snapshot here
# taking size into account
img = self.get_snapshot(site, size)
# img now either is the snapshot from the cache or a
placeholder image
cherry.serve_file(img, 'image/jpg')
def get_snapshot(self, site, size):
"""This is where the magic happens"""
return join(self.cache_dir, md5.new(site + str(size)).hexdigest())
Cool, this seems like exactly the kind of thing I was looking for!
Chris
I use PIL on http://mydrawings.com and it works great.
http://www.pythonware.com/products/pil/
And how do you control the browser?
Anyway, the link Richard pointed out (khtml2png) lead to another, Python based
solution, that can take snapshots from a GTK window with an embedded Mozilla
rendering engine:
http://www.burtonini.com/blog/computers/mozilla-thumbnail-20040614.xhtml
Now I just need to find the time to wrap up one (or both) solution(s) into a
plug-n-play widget for TG.
Chris