quick simple choose thumbs script

will choose second image in the gallery as the thumb. this drastically speeds up page loads, especially during dev ;)

<?php

$dbserver = 'localhost';
$dbuser = 'foo';
$dbpass = 'bar';
$dbname = 'photozen';

$zprootdir = 'C:/xampp/htdocs/zp/albums/'; // full file path to albums dir

mysql_connect($dbserver, $dbuser, $dbpass);
mysql_select_db($dbname);

$query = 'SELECT id, folder FROM zp_albums WHERE thumb is NULL AND parentid IS NOT NULL';

$rs = mysql_query($query);

while (($row = mysql_fetch_assoc($rs))){
// choose second image from dir
$images = glob($zprootdir . $row['folder'] . '/*.{jpg,JPG,jpeg,png,gif}', GLOB_BRACE);
natsort($images);
$thumb = $images[1]; // change to choose the number image you want as thumb (always one less)

// keep just filename remove 'sites/site-title'
$thumb = substr($thumb, strrpos($thumb, '/')+1);

// update db
mysql_query("UPDATE zp_albums SET thumb = '" . mysql_real_escape_string($thumb) . "' WHERE id = " . $row['id']);
}
die ("all done");

?>

Comments

  • I'm confused about this. Is this the config file? Is this a complete replacement for it? I'm always looking for ways to increase speed. When I try the "performance hacks" they never seem to work... where does this go?
  • This is a special script that you would run.

    However, You might just want to choose the thumbnail from the album edit page. There you can choose from any image in the album.
  • trisweb Administrator
    Looks like this is a script that you run once to set the thumbnails for each album so they aren't random.

    The only reason you'd do this, as george2 said, is if you're developing and don't want to load/process thumbnails from large albums.

    You get the same effect in production by just setting the album thumb manually, which you'd probably want to do anyway.
  • thanks. The support here is great. I might actually have a use for this anyway
  • My client is choosing a thumbnail from every album, yet her galleries are displaying the first image in the album as the thumbnail (if I choose 'manual image' sorting instead of 'filename', it picks some random image from the middle). Any ideas why this feature isn't working? Should I delete all the thumbnails except the chosen one from the cache?

    Here is the gallery in question:

    http://www.lindsayhutchens.com/archive

    Thanks!
Sign In or Register to comment.