Esempio n. 1
0
function spit_phpthumb_image($filepath, $configarray = array())
{
    // set up class
    global $CFG, $PHPTHUMB_CONFIG;
    $phpThumb = new phpThumb();
    // import default config
    if (!empty($PHPTHUMB_CONFIG)) {
        foreach ($PHPTHUMB_CONFIG as $key => $value) {
            $keyname = 'config_' . $key;
            $phpThumb->setParameter($keyname, $value);
        }
    }
    // import passed params
    if (!empty($configarray)) {
        foreach ($configarray as $key => $value) {
            $keyname = $key;
            $phpThumb->setParameter($keyname, $value);
        }
    }
    $phpThumb->setSourceFilename($filepath);
    if (!is_file($phpThumb->sourceFilename) && !phpthumb_functions::gd_version()) {
        if (!headers_sent()) {
            // base64-encoded error image in GIF format
            $ERROR_NOGD = 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
            header('Content-Type: image/gif');
            echo base64_decode($ERROR_NOGD);
        } else {
            echo '*** ERROR: No PHP-GD support available ***';
        }
        exit;
    }
    $phpThumb->SetCacheFilename();
    if (!file_exists($phpThumb->cache_filename) && is_writable(dirname($phpThumb->cache_filename))) {
        //         error_log("generating to cache: " . $phpThumb->cache_filename);
        $phpThumb->CleanUpCacheDirectory();
        $phpThumb->GenerateThumbnail();
        $phpThumb->RenderToFile($phpThumb->cache_filename);
    }
    if (is_file($phpThumb->cache_filename)) {
        //         error_log("sending from cache: " . $phpThumb->cache_filename);
        if ($getimagesize = @GetImageSize($phpThumb->cache_filename)) {
            $mimetype = phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]);
        }
        spitfile_with_mtime_check($phpThumb->cache_filename, $mimetype);
    } else {
        //         error_log("phpthumb cache file doesn't exist: " . $phpThumb->cache_filename);
        $phpThumb->GenerateThumbnail();
        $phpThumb->OutputThumbnail();
        exit;
    }
}
Esempio n. 2
0
} else {
    phpthumb_functions::EnsureDirectoryExists(dirname($phpThumb->cache_filename));
    if (@file_exists($phpThumb->cache_filename) && is_writable($phpThumb->cache_filename) || is_writable(dirname($phpThumb->cache_filename))) {
        $phpThumb->CleanUpCacheDirectory();
        if ($phpThumb->RenderToFile($phpThumb->cache_filename) && is_readable($phpThumb->cache_filename)) {
            chmod($phpThumb->cache_filename, 0644);
            RedirectToCachedFile();
        } else {
            $phpThumb->DebugMessage('Failed: RenderToFile(' . $phpThumb->cache_filename . ')', __FILE__, __LINE__);
        }
    } else {
        $phpThumb->DebugMessage('Cannot write to $phpThumb->cache_filename (' . $phpThumb->cache_filename . ') because that directory (' . dirname($phpThumb->cache_filename) . ') is not writable', __FILE__, __LINE__);
    }
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[9]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '9') {
    $phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
if (!$phpThumb->OutputThumbnail()) {
    $phpThumb->ErrorImage('Error in OutputThumbnail():' . "\n" . $phpThumb->debugmessages[count($phpThumb->debugmessages) - 1]);
}
////////////////////////////////////////////////////////////////
// Debug output, to try and help me diagnose problems
$phpThumb->DebugTimingMessage('phpThumbDebug[10]', __FILE__, __LINE__);
if (@$_GET['phpThumbDebug'] == '10') {
    $phpThumb->phpThumbDebug();
}
////////////////////////////////////////////////////////////////
    // here you must preface each option with "config_"
    $phpThumb->setParameter('config_output_format', 'jpeg');
    $phpThumb->setParameter('config_imagemagick_path', '/usr/local/bin/convert');
    //$phpThumb->setParameter('config_allow_src_above_docroot', true); // needed if you're working outside DOCUMENT_ROOT, in a temp dir for example
    // generate & output thumbnail
    $output_filename = './thumbnails/' . basename($_FILES['userfile']['name']) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format;
    if ($phpThumb->GenerateThumbnail()) {
        // this line is VERY important, do not remove it!
        if ($output_filename) {
            if ($capture_raw_data && $phpThumb->RenderOutput()) {
                // RenderOutput renders the thumbnail data to $phpThumb->outputImageData, not to a file or the browser
                mysql_query("INSERT INTO `table` (`thumbnail`) VALUES ('" . mysql_escape_string($phpThumb->outputImageData) . "') WHERE (`id` = '" . $id . "'");
            } elseif ($phpThumb->RenderToFile($output_filename)) {
                // do something on success
                echo 'Successfully rendered:<br><img src="' . $output_filename . '">';
            } else {
                // do something with debug/error messages
                echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
            }
        } else {
            $phpThumb->OutputThumbnail();
        }
    } else {
        // do something with debug/error messages
        echo 'Failed (size=' . $thumbnail_width . ').<br>';
        echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">' . $phpThumb->fatalerror . '</div>';
        echo '<form><textarea rows="10" cols="60" wrap="off">' . htmlentities(implode("\n* ", $phpThumb->debugmessages)) . '</textarea></form><hr>';
    }
    // remember to unset the object each time through the loop
    unset($phpThumb);
}
Esempio n. 4
0
function processEPC($photo, $dea_id)
{
    require_once dirname(__FILE__) . "/phpThumb/phpthumb.class.php";
    $errors = '';
    $thumbnail_sizes = array('full' => array('h' => '600'), 'large' => array('h' => '600'), 'small' => array('w' => '200'), 'thumb1' => array('w' => '146', 'h' => '146'), 'original' => array('h' => '', 'w' => ''));
    $image_path_property = IMAGE_PATH_PROPERTY . $dea_id . "/";
    $image_url_property = IMAGE_URL_PROPERTY . $dea_id . "/";
    $attributes = getimagesize($image_path_property . $photo);
    foreach ($thumbnail_sizes as $ext => $dims) {
        if (isset($dims['w']) && $dims['w']) {
            $dims['w'] = $attributes[0] < $dims['w'] ? $attributes[0] : $dims['w'];
        }
        if (isset($dims['h']) && $dims['h']) {
            $dims['h'] = $attributes[1] < $dims['h'] ? $attributes[1] : $dims['h'];
        }
        // only process images that are big enough
        $phpThumb = new phpThumb();
        // set data
        $phpThumb->setSourceFilename($image_path_property . $photo);
        if (isset($dims['w']) && $dims['w']) {
            $phpThumb->setParameter('w', $dims['w']);
        }
        if (isset($dims['h']) && $dims['h']) {
            $phpThumb->setParameter('h', $dims['h']);
        }
        $phpThumb->setParameter('config_output_format', 'gif');
        $phpThumb->setParameter('config_allow_src_above_docroot', true);
        // generate & output thumbnail
        $output_filename = $image_path_property . str_replace('.gif', '', $photo) . '_' . $ext . '.' . $phpThumb->config_output_format;
        if ($phpThumb->GenerateThumbnail()) {
            // this line is VERY important, do not remove it!
            $output_size_x = ImageSX($phpThumb->gdimg_output);
            $output_size_y = ImageSY($phpThumb->gdimg_output);
            if ($output_filename) {
                if ($phpThumb->RenderToFile($output_filename)) {
                    // do something on success
                    #echo 'Successfully rendered:<br><img src="'.$output_filename.'">';
                } else {
                    // do something with debug/error messages
                    echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
                }
            } else {
                $phpThumb->OutputThumbnail();
            }
        } else {
            // do something with debug/error messages
            $errors .= '<p>Failed (size=' . $thumbnail_width . ').<br>
				<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">' . $phpThumb->fatalerror . '</div>
				<form><textarea rows="10" cols="60" wrap="off">' . htmlentities(implode("\n* ", $phpThumb->debugmessages)) . '</textarea></form></p><hr>';
        }
    }
    if ($errors) {
        echo $errors;
        exit;
    }
}
Esempio n. 5
0
function generateThumb($imgDir, $picName, $extension, $thumbtext)
{
    require_once '../thumb/phpthumb.class.php';
    require '../variables.php';
    $thumbNames = array();
    $imgUrl = $imgDir . $picName . "." . $extension;
    $thumbDir = "thumbnails/";
    // echo "<p>$imgUrl</p>";
    // create 3 sizes of thumbnail
    $thumbnail_widths = getThumbnailWidths();
    foreach ($thumbnail_widths as $thumbnail_width) {
        // Note: If you want to loop through and create multiple
        //   thumbnails from different image sources, you should
        //   create and dispose an instance of phpThumb() each time
        //   through the loop and not reuse the object.
        $phpThumb = new phpThumb();
        // set data
        $phpThumb->setSourceFilename($imgUrl);
        // or $phpThumb->setSourceData($binary_image_data);
        // or $phpThumb->setSourceImageResource($gd_image_resource);
        // $gd_img = imagecreatefrom($imgPath.$picturename);
        // $phpThumb->setSourceImageResource($gd_img);
        // set parameters (see "URL Parameters" in phpthumb.readme.txt)
        $phpThumb->setParameter('w', $thumbnail_width);
        //$phpThumb->setParameter('h', 100);
        $fParam = 'wmt|Click to open (^Xx^Y)|1|B|FFFFFF||100|0||000000|100|x';
        if (!empty($thumbtext)) {
            $fParamTop = 'wmt| ' . $thumbtext . ' |2|T|000000||100|0||CCCCCC|100|x';
            $phpThumb->setParameter('fltr', $fParamTop);
        }
        $phpThumb->setParameter('fltr', $fParam);
        $phpThumb->setParameter('fltr', 'bord|1');
        // set options (see phpThumb.config.php)
        // here you must preface each option with "config_"
        $phpThumb->setParameter('config_output_format', 'png');
        // $phpThumb->setParameter('config_imagemagick_path', '/usr/local/bin/convert');
        // $phpThumb->setParameter('config_imagemagick_path', '.');
        //$phpThumb->setParameter('config_allow_src_above_docroot', true); // needed if you're working outside DOCUMENT_ROOT, in a temp dir for example
        // generate & output thumbnail
        $output_filename = $imgDir . $thumbDir . $picName . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format;
        if ($phpThumb->GenerateThumbnail()) {
            // this line is VERY important, do not remove it!
            if ($output_filename) {
                if ($capture_raw_data && $phpThumb->RenderOutput()) {
                    // RenderOutput renders the thumbnail data to $phpThumb->outputImageData, not to a file or the browser
                    // mysql_query("INSERT INTO `table` (`thumbnail`) VALUES ('".mysql_escape_string($phpThumb->outputImageData)."') WHERE (`id` = '".$id."'");
                } elseif ($phpThumb->RenderToFile($output_filename)) {
                    $thumbNames[] = array($thumbnail_width, $output_filename);
                } else {
                    // do something with debug/error messages
                    // echo 'Failed (size=' . $thumbnail_width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>';
                }
            } else {
                $phpThumb->OutputThumbnail();
            }
        } else {
            // do something with debug/error messages
            //echo '<p>Thumbnail generation failed (size='.$thumbnail_width.').</p>';
            //echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">'.$phpThumb->fatalerror.'</div>';
            //echo '<form><textarea rows="10" cols="60" wrap="off">'.htmlentities(implode("\n* ", $phpThumb->debugmessages)).'</textarea></form><hr>';
        }
        // remember to unset the object each time through the loop
        unset($phpThumb);
    }
    return $thumbNames;
}