CleanUp/ThumbnailGeneration

  • Problem 1 - make it easy for the user to add new thumbnail sizes
  • Problem 2 - create more reliable thumbnail refresh conditions, this is ticket #67

Possible solution - it's not quite fleshed out yet

First, create a SQL table with the following structure for thumbnail configuration:

mysql> describe plogger_thumbnails_config;
+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| id               | int(10) unsigned |      | PRI | NULL    | auto_increment |
| update_timestamp | int(10) unsigned | YES  |     | NULL    |                |
| max_size         | int(10) unsigned | YES  |     | NULL    |                |
+------------------+------------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

When Plogger is installed, 3 rows get inserted into this table, one for each currently used thumbnail type and update_timestamp gets set to NOW() (current timestamp)

Secondly, create a new user interface (under Options perhaps?), which will then allow editing of existing thumbnail types and will also allow adding of new types and configurations.

Updating a record in this table will modify update_timestamp field (by setting it to current timestamp again)

generate_thumbnail() in plog-functions.php will then compare the 'file created' timestamp of already existing thumbnail file and the one in thumbnails_config and create a new file - if needed.

Adding new thumbnail sizes (and perhaps even removing existing ones) will be a lot easier and Plogger will be a lot more flexible as a result.

Unsorted ideas:

  • Each row could have a separate field for compression, with the default being 75 (like now). This allows for higher quality big thumbnails and low quality small thumbnails.
  • Why different sizes? Take a look at http://www.flickr.com/photo_zoom.gne?id=45130413&size=m - there are 5 different ones, seems quite handy

(information below that line describes the current implementation)


Thumbnail configuration takes place in plog-load_config.php. If there will ever be need for a new type of thumbnail, then it's definition should be added here.

$thumbnail_config = array();
$thumbnail_config['small'] = array('filename_prefix => '','width' => $config['max_thumbnail_size']);
$thumbnail_config['large'] = array('filename_prefix => 'lrg-','width' => $config['max_display_size']);
$thumbnail_config['rss'] = array('filename_prefix => 'rss-','width' => $config['rss_thumbsize']);

The actual thumbnail generation code is in generate_thumb() function which is located in plog-functions.php. It takes 3 arguments:

  • path to the image file for which a thumbnail should be generated. Relative to the images/ directory
  • prefix - all thumbnails are stored in a single directory, having a prefix is required to avoid conflicts if there are images with similar names in different albums
  • type - (small|large|rss) - pointer to the key in $thumbnail_config
$thumburl = generate_thumb("somepicture.jpg",$prefix,"large");
function generate_thumb($path,$prefix,$type) {
    global $thumbnail_config;
    $thumbnail_details = $thumbnail_config[$type];
    // generate the proper thumbnail

Having a config variable for thumbnails allows for easier cleanup when a picture is deleted . The deletion code could just iterates over $thumbnail_config and deletes all matching filess.