activate https

Fuer die deutsche Version hier klicken.


This script basically shows the content of a directory with thumbnailed versions of the included images or it shows different quality versions of an image. The main intention was to be very fast and easy.

Live Demonstration: my picture collection


The recent version also includes a caching system for the images. In the past, the preview-image was always generated on-the-fly which is of course very slow (imagine a directory with 100 pictures in it and on each request the script had to generate 100 thumbnails).
The PHP-script will save the generated preview-image in /var/tmp/pics/ at the moment, though you can easily change this. It generates the pictures the first time you request it and uses the cache after (if it is not older than the image).


I use some URL-rewrite-rules to map the URL (like ".../pics/finland/" or "../pics/picture.jpg") to the PHP-script. In lighttpd, these are the following rules:

url.rewrite = (
    "^/pics/(.*)\?get" => "/pics/$1",
    "^/pics/(.*)/\?(.*)type=pic(.*)" => "/pics/pic.cml?dir=$1&$2$3",
    "^/pics/(.*)/\?(.*)" => "/pics/pics.php?dir=$1&$2",
    "^/pics/(.*)\?(.*)" => "/pics/pics.php?dir=$1&$2",
    "^/pics/(.*)" => "/pics/pics.php?dir=$1" )

In Apache, I use the following ruleset:

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule "^(.*/)?pics/(.*/)?$" "$1pics/pics.php?dir=$2" [last,QSA]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule "^/var/www/localhost/htdocs/(.*/)?pics/(.*)$" "/$1pics/$2/" [R,last,QSA]

RewriteCond %{QUERY_STRING} =get
RewriteRule "^(.*/)?pics/(.*)$" "$1pics/$2" [last]

RewriteCond %{REQUEST_FILENAME} !(.*)/pics.php
RewriteRule "^(.*/)?pics/(.*)$" "$1pics/pics.php?dir=$2" [last,QSA]


I also use mod_cml as you can see from the rules. This increases the speed a lot, especially in the case of a big amount of pictures in a directory. The pic.cml script basically checks if there is already a cached version of the requested image and if this is up-to-date and in this case, it just returns this cached image. In all other cases it runs the PHP-script.
I have also added this routine in the PHP-script in case you don't want to use mod_cml but though you want the use of the caches. Though as I said, PHP is much slower by doing this and forwarding the data of the cached image. It should be sufficient in the rewrite-rules to replace "pic.cml" with "pics.php".
(Currently, mod_cml does not exist for Apache. But at recent times, I have updated the pics.php that it is also fast without mod_cml.)


Source Code: pics.php

If you want to support my work, please donate via Gittip/Flattr here:

The program published here is under the copyright of Albert Zeyer. In that case there is the source code to download, it is under the LGPL-licence. Distributions of it are only allowed with a reference to this page.

- Other projects
- Mainsite


Albert Zeyer (Mail)

You are the 2277021th thing, which loves this site.

Quote of the day

"No, no, do the goldfish!" tongued the ear licking housewife as the bung-hole stuffing friar slurped her pendulous eyes and pounded his warty stick shift into her soft-spoken jam jar.


13:48:38 up 1368 days, 19:30, 10 users, load average: 0.00, 0.02, 0.05

About this homepage

The code can be seen here. Please contact me if you find any problems. :)