Generating a Thumbnail by the API

176 views Asked by At

By default, phpThumb generates a thumb the first time it is requested. I need to generate it immediately after the image is uploaded to save time when it is requested. I understand that Line 549 of phpThumb.class.php is the focal point of the solution:

$phpThumb->GenerateThumbnail();

However, I'm not sure how much of the surrounding code I should take with it. It looks like I need the next 42 lines (that chain of if's and else's), but, as I'm not familiar with these internals and I couldn't find API documentation for this file, here I am.

(Is there a version number somewhere in the source files that I can post?)

Thanks for any help.

1

There are 1 answers

0
Alistair On

If it's of any use I'm using PHPThumb 3 and have the following PHP code to generate a thumbnail:

<?php
if (!file_exists($thumbnailFile)) {
    try {
        $thumb = PhpThumbFactory::create($imageFile);
        $thumb->adaptiveResize(60, 60);
        $thumb->save($thumbnailFile, 'png');
    } catch (Exception $e) {
        //Zend_Debug::dump($e);
        throw new Exception('Issue generating thumbnails');
    }
}

Perhaps that's enough for you to adapt to what you need?