How to Create Website Thumbnails with PHP and Firefox

Being able to create thumbnail images of websites can be particularly useful as a website owner, visitors, and generally aesthetically pleasing to appear on a page.

There are a number of ways you can create thumbnails, some better than others, while some lack fairly essential features like the ability to render flash before the thumbnail image is generated. Without that particular feature, flash website thumbnails appear like blank pages.

Here are two options that are available to you and can be adjusted accordingly, one exclusively for linux users:

PHP / Firefox

If you are a firefox user, I recommend getting the Pearl Crescent Page Saver plugin for Firefox. A free and paid version is available, with the latter offering slightly more features should you have the requirement of them.

The basic requirements of the script are:

  • PHP: Or any other scripting language that can iterate through the list of URLs you would like to make thumbnails of
  • Firefox: The browser that is used to render webpages you want to make thumbnails of
  • Page Saver Plugin: The plugin that interacts with Firefox to generate a thumbnail
  • ImageMagick: Not essential, but is very handy for post-processing of images, i.e. resizing.
  • Access to the command line

If you do not have Imagemagick installed, you will want to remove the last 2 lines of code as it involves resizing the image.

Note that you will want to close all your browser windows while testing out this script, or at least create a separate firefox profile. Ideally you would run a separate firefox profile as well as on a separate display/screen.

As an aside, I enjoy using the Firefox browser extenson MozRepl… and there’s a nice github on how to use the Firefox internals (Javascript, essentially), to create screenshots. This will remove the need to install the Pearl Crescent extension, though that particular extension has some nice customisation built in.

Bash / Konqueror

I am using Ubuntu, your flavour of Linux may require different commands. The following packages/software are required for the bash script to run correctly:

Save the following as

Save the following as thumbnails.txt and also create a directory for the thumbnails to reside in, for example /var/www/thumbs/

The following command will then iterate through the list in thumbnails.txt

Some notes regarding the latter script and both methods in general

  • I use PHP to generate the thumbnails.txt input files, the bash script iterates through each line and accesses the $URL and saves the thumbs with the filename $URLID in each line
  • Xvfb initiates a mock display that konqueror uses to render web pages. You don’t actually need to see the browser working through the list
  • You may want to have a default page and load that up before calling each URL. This is so that a ‘default thumb’ can be used when a webpage is very slow to load.
  • You have to shut the browser down before running these scripts, otherwise browser invocation will complain that the browser is already running. This is why I like the Konqueror bash script more, as I use Firefox to browse. Alternatively, you can set up separate firefox profiles that won’t cause the program to grumble when you invoke a new window.

There are lots of solutions in acquiring screenshots, these are just a couple of ways to give you an idea of how it is done.

Leave a Reply

Your email address will not be published. Required fields are marked *