How to Create Website Thumbnails with PHP and Firefox

Page last updated on 2011 / 04 / 09

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:

  1. <?php
  2. $sites = array('http://www.innvo.com/','http://www.yahoo.com/','http://www.google.co.uk/');
  3. foreach($sites as $key => $site)
  4. {
  5. $file = './'.$key.'.jpg';
  6. $string = 'firefox -saveoptions visible -captureflash -savedelay 1500 -width 1024 -height 768 -saveimage "'.$site.'" -saveas '.$file;
  7. `$string`;
  8. $string = 'convert '.$file.' -resize 300x180 _'.$key.'.jpg';
  9. `$string`;
  10. }
  11. ?>
  12.  

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.

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 thumbnails.sh

  1. #!/bin/bash
  2.  
  3. pkill -x "(Xvfb)" & sleep 1;
  4. pkill -x "(konqueror)" & sleep 1;
  5. pkill -x "(fluxbox)" & sleep 1;
  6. Xvfb :10 -auth /etc/X11.hosts -once -screen 0 1024x768x24 & sleep 3;
  7. export DISPLAY=:10;
  8. fluxbox & sleep 0;
  9. konqueror --geometry 1024x740 & sleep 2;
  10. for i in `cat -T $1`; do
  11. URL=${i%^I*}
  12. URLID=${i#*^I}
  13. qdbus `qdbus | grep -m1 konqueror` /konqueror/MainWindow_1 org.kde.Konqueror.MainWindow.openUrl $URL false
  14. sleep 10;
  15. import -display :10 -w root $2$URLID.jpg;
  16. convert $2$URLID.jpg -crop 1000x578+2+138 $2$URLID.jpg;
  17. convert $2$URLID.jpg -resize 128x73 $2\_$URLID.jpg;
  18. convert $2$URLID.jpg -resize 300x180 $2$URLID.jpg;
  19. done;
  20. pkill -x "(konqueror)" & sleep 0;
  21. pkill -x "(fluxbox)" & sleep 0;
  22. pkill -x "(Xvfb)" & sleep 0;
  23.  
  24.  

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

http://www.google.com/ 1
http://www.yahoo.com/ 2
http://www.innvo.com/ 3

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

sh thumbnails.sh thumbnails.list /var/www/thumbs/

Some notes regarding the latter script and both methods in general


Previous Article
Colour Coding PHP Output in HTML
Next Article
A Simple PHP/XML Sitemap Generator




Tweet