Website thumbnail genaration on Linux?

3 views
Skip to first unread message

Christopher Arndt

unread,
Dec 5, 2006, 8:45:43 PM12/5/06
to turbo...@googlegroups.com
Hi all,

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

thesamet

unread,
Dec 6, 2006, 1:00:45 AM12/6/06
to TurboGears
You can make a shell script that just captures an image, and launch it
from python using os.system().
In that script, start firefox on a vnc server, wait for a fixed amount
of seconds (for the web site to load), and then execute the
command-line utility import, to capture the screen or just firefox
window.

Nadav

thesamet

unread,
Dec 6, 2006, 1:00:45 AM12/6/06
to TurboGears

Diez B. Roggisch

unread,
Dec 6, 2006, 4:14:18 AM12/6/06
to turbo...@googlegroups.com
Christopher Arndt schrieb:

> Hi all,
>
> 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.

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

Arthur Clune

unread,
Dec 6, 2006, 4:57:03 AM12/6/06
to turbo...@googlegroups.com

On 6 Dec 2006, at 09:14, Diez B. Roggisch wrote:

>> 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

Christopher Arndt

unread,
Dec 6, 2006, 5:01:28 AM12/6/06
to turbo...@googlegroups.com
Diez B. Roggisch wrote:
> 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.

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())

Richard (koorb)

unread,
Dec 6, 2006, 5:34:08 AM12/6/06
to TurboGears
I think this may be of some use to you http://khtml2png.sourceforge.net/

Richard (koorb)

unread,
Dec 6, 2006, 5:35:01 AM12/6/06
to TurboGears
Of course I use this on a mac http://www.paulhammond.org/webkit2png/

Christopher Arndt

unread,
Dec 6, 2006, 5:56:59 AM12/6/06
to turbo...@googlegroups.com
Richard (koorb) schrieb:

> I think this may be of some use to you http://khtml2png.sourceforge.net/

Cool, this seems like exactly the kind of thing I was looking for!

Chris

Dennis Muhlestein

unread,
Dec 6, 2006, 2:59:06 PM12/6/06
to TurboGears
On Dec 5, 6:45 pm, Christopher Arndt <chris.ar...@web.de> wrote:
> Hi all,
>
> 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 use PIL on http://mydrawings.com and it works great.
http://www.pythonware.com/products/pil/

Christopher Arndt

unread,
Dec 6, 2006, 4:29:57 PM12/6/06
to turbo...@googlegroups.com
Dennis Muhlestein schrieb:

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

Reply all
Reply to author
Forward
0 new messages