regenerate thumbnails in cache via script

i'd like to be able to trigger thumbnail creation via script, after adding a large number of files, to save generating them on the fly. with over 10GB of images & adding about 1GB per month, it makes sense to be able to do this in advance, to keep load down

Comments

  • trisweb Administrator
    Quite easy. This will load a page of all thumbnails and default-sized images in your gallery:

    `

    <?php <br />
    require_once("zen/template-functions.php");

    $count = 0;

    echo 'Loading...
    ';

    while (next_album()):

    while (next_image()):

    echo 'image / image
    ';

    $count++;

    endwhile;

    endwhile;

    echo "Finished: Total of $count images.

    ";

    ?>

    `
  • thanks!

    I dropped this in zen/* with all the other bits as rebuild.php, stripped out the zen/ path header & ran it, with a ."\n" at the end of the echo line for readability:

    php rebuild.php
    <.../

    Finished: Total of 459 images.

    -- in about 10 seconds. i'm a little suspicious as i know i have 9000 images online so far... and only 530 thumbnails in cache/

    the first folder it picks up has about 350 images in it, but ZP only gets to the first 30 before heading off to the next ones. this is a pattern - if the album has > 30 images, ZP skips to the next before finishing.

    i'd guess there needs to be something like a "next page" in between the next_album and next_image loops...

    i can provide debug output or any other info if you let me know what is needed.

    you can grab the log from this run as:

    http://muse.net.nz/zenphoto/cache/rebuild.log

    thanks, scorch

    PS i still haven't figured out how/where i can rotate images yet ... is there a how-to somewhere i missed?
  • trisweb Administrator
    Oh right, that may help.... heh. Try this (Improved in other ways as well):

    `

    <?php <br />
    require_once("zen/template-functions.php");

    $count = 0;

    echo 'Loading...
    ';

    $_zp_page = 0;

    while (next_album()) {

    while (next_image()) {

    echo 'imageimage'."n";

    $count++;

    if ($count % 20 == 0) echo "
    n";

    }

    }

    echo "n
    Finished: Total of $count images.

    ";

    ?>

    `
  • that works nicely thanks - but only if it's under zenphoto/rebuild.php

    is it possible to change to run from zephoto/zen/ & then leave it in SVN? that would be a useful addition.

    e.g. as http://muse.net.nz/zenphoto/zen/rebuild.php
  • trisweb Administrator
    To change it for that, just take the `zen/` out of the require_once path string. I don't think I'll check it in to SVN just yet, perhaps a similar functionality will be in the 1.1 admin though.
  • thanks! just a point - this takes hours to run through. if you ever move it into svn, it would be a good move to add it as a button to a folder level "regenerate" for example.
  • Sorry to revive an old thread but I am really looking for this functionality but I heavily use sub-albums and this script is not decending into the sub-albums. Is there a quick change to the script that would help? Thanks in advance.
  • same here, any hope for a recursive version of this ?
  • Anyone figure out a way to get this working for subalbums yet? This would be a very useful script to have in the admin page.
  • Here is a routine which will do what you want. Copy it into your zen folder with the rest of the php files. Then point your browser to it.

    `

    <?php <br />
    require_once("template-functions.php");

    global $_zp_gallery;

    $count = 0;

    function loadAlbum($album) {

    global $_zp_current_album;

    echo "
    Processing " . $album->name . "n";

    $subalbums = $album->getSubAlbums();

    foreach ($subalbums as $folder) {

    $subalbum = new Album($album, $folder);

    $count = $count + loadAlbum($subalbum);

    }

    $_zp_current_album = $album;

    if (getNumImages() > 0) {

    echo "
    n";

    while (next_image()):

    echo 'image | image' . "n";

    $count++;

    endwhile;

    }

    echo "
    Finished with " .$album->name . "n";

    return $count;

    }

    if (isset($_GET['album'])) {

    $folder = strip($_GET['album']);

    $album = new Album($album, $folder);

    $count = loadAlbum($album);

    } else {

    echo "Processing Galleryn";

    $albums = $_zp_gallery->getAlbums();

    foreach ($albums as $folder) {

    $album = new Album($album, $folder);

    $count = $count + loadAlbum($album);

    }

    }

    echo "
    Finished: Total of $count images.";

    ?>

    `

    If you don't want to do your whole gallery, just pass the file an album parameter with the name of the album you wish to process.

    e.g. http://myalbum.zenphoto.com/zenphoto/zen/loadAlbums.php?album=newalbum
  • I'm using the latest script from sbillard on zenphoto 1.2.2. getNumImages() returns the count of images for each album but next_image() doesn't seem to be returning any images.

    Any ideas why? Does anyone have an updated cache script? (I need it for my gallery migration)

    Thanks,

    grantonstar
  • 1.1.2 has the pre-cache images utility, why don't you use that.
  • THe main reason why is because it is unable to cache 17k images at once. Either it times out or the browser crashes.

    The reason I want to pre-cache is to run the Gallery migration utility.
  • Pre-cache by album/subalbum. What makes you think the above script will not also time out? It is, after all, basically the same code as the pre-cache utility.
  • Are there any includes or bootstrapping code I need to add to the script to run it from the command line of the web server rather than through a browser? I'm working with images that are hundreds of MB, and I'm not allowed to change the web server's memory limits, but I can override the PHP memory limit on the command line.
  • acrylian Administrator, Developer
    This topic is really old. Zenphoto features a cache_manager plugin that took over the older precache functionality.
  • acrylian Administrator, Developer
    This topic is really old. Zenphoto features a cache_manager plugin that took over the older precache functionality.
Sign In or Register to comment.