Build your own website thumbnail generator with Django

On many website you can see a awesome link preview effect using a thumbnail of the page. There is some web services such as Websnapr or Thumbalizr providing an API to make your own webpages screenshots but it can be annoying to rely on third party projects: free accounts can only display a small among of screenshots and, cannot customize the size of the image, you cannot render Flash animations or Javascript…

Webkit Logo

We will build a website thumbnail generator using CutyCapt, a Webkit based free software designed to make screenshots of web pages, and Django, the powerful Python web framework.

The first step is to download and install CutyCapt. On a Debian-based system (such as Ubuntu) just type the following commands:

Try to open the example.png (i.e: eog example.png), if the install is OK you must see a screenshot of this blog.

I assume your Django installation is working fine. Start a new project if needed ( startproject mysite) and create an application called webthumb

with python startapp in your project.

Django Reinhardt

Edit your file to add a new pattern to the tuple urlpatterns. It will match screenshots requests and call the thumb view:

Now create a view called thumb in webthumb/ with this code:

Adapt the variables CUTYCAPT and THUMBS_DIR with your settings. Of course the directory pointed by THUMBS_DIR must be writeable (chmod 777).

You can now embed website thumbnails in your websites just with this HTML markup <img src="http://localhost/thumb///" alt="Lapin Blanc" />.

Enjoy !

The last update of Aptana block Django development server

The last update of Aptana Studio come with a new built-in Jetty-based HTTP server running on port 8000… the same as Django development server. There is no good way to disable the preview server feature of the popular editor, but our favorite web framework can be launched on another port. Just type python runserver 8080 instead of python and access to your work on http://localhost:8080.

Django logo

Ravalement de façade

Comme vous pouvez le voir, j’ai légerement remanié l’apparence de mon blog. Il utilise désormais un thème très sobre à trois colonnes permettant de mieux structurer l’information et fait la part belle à Twitter que j’utilise de plus en plus assidument.