function RedirectToCachedFile() { global $phpThumb; $nice_cachefile = str_replace(DIRECTORY_SEPARATOR, '/', $phpThumb->cache_filename); $nice_docroot = str_replace(DIRECTORY_SEPARATOR, '/', rtrim($phpThumb->config_document_root, '/\\')); $parsed_url = phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']); $nModified = filemtime($phpThumb->cache_filename); if ($phpThumb->config_nooffsitelink_enabled && !empty($_SERVER['HTTP_REFERER']) && !in_array(@$parsed_url['host'], $phpThumb->config_nooffsitelink_valid_domains)) { $phpThumb->DebugMessage('Would have used cached (image/' . $phpThumb->thumbnailFormat . ') file "' . $phpThumb->cache_filename . '" (Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT), but skipping because $_SERVER[HTTP_REFERER] (' . @$_SERVER['HTTP_REFERER'] . ') is not in $phpThumb->config_nooffsitelink_valid_domains (' . implode(';', $phpThumb->config_nooffsitelink_valid_domains) . ')', __FILE__, __LINE__); } elseif ($phpThumb->phpThumbDebug) { $phpThumb->DebugTimingMessage('skipped using cached image', __FILE__, __LINE__); $phpThumb->DebugMessage('Would have used cached file, but skipping due to phpThumbDebug', __FILE__, __LINE__); $phpThumb->DebugMessage('* Would have sent headers (1): Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT', __FILE__, __LINE__); if ($getimagesize = @getimagesize($phpThumb->cache_filename)) { $phpThumb->DebugMessage('* Would have sent headers (2): Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]), __FILE__, __LINE__); } if (preg_match('#^' . preg_quote($nice_docroot) . '(.*)$#', $nice_cachefile, $matches)) { $phpThumb->DebugMessage('* Would have sent headers (3): Location: ' . dirname($matches[1]) . '/' . urlencode(basename($matches[1])), __FILE__, __LINE__); } else { $phpThumb->DebugMessage('* Would have sent data: readfile(' . $phpThumb->cache_filename . ')', __FILE__, __LINE__); } } else { if (headers_sent()) { $phpThumb->ErrorImage('Headers already sent (' . basename(__FILE__) . ' line ' . __LINE__ . ')'); exit; } SendSaveAsFileHeaderIfNeeded(); header('Pragma: private'); header('Cache-Control: max-age=' . $phpThumb->getParameter('config_cache_maxage')); header('Expires: ' . date(DATE_RFC1123, time() + $phpThumb->getParameter('config_cache_maxage'))); if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $nModified == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !empty($_SERVER['SERVER_PROTOCOL'])) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT'); header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); exit; } header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $nModified) . ' GMT'); header('ETag: "' . md5_file($phpThumb->cache_filename) . '"'); if ($getimagesize = @getimagesize($phpThumb->cache_filename)) { header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2])); } elseif (preg_match('#\\.ico$#i', $phpThumb->cache_filename)) { header('Content-Type: image/x-icon'); } header('Content-Length: ' . filesize($phpThumb->cache_filename)); if (empty($phpThumb->config_cache_force_passthru) && preg_match('#^' . preg_quote($nice_docroot) . '(.*)$#', $nice_cachefile, $matches)) { header('Location: ' . dirname($matches[1]) . '/' . urlencode(basename($matches[1]))); } else { @readfile($phpThumb->cache_filename); } exit; } return true; }
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; } }
/** PHPTHUMB HELPER METHODS **/ public function RedirectToCachedFile() { $nice_cachefile = str_replace(DIRECTORY_SEPARATOR, '/', $this->cache_filename); $nice_docroot = str_replace(DIRECTORY_SEPARATOR, '/', rtrim($this->config_document_root, '/\\')); $parsed_url = phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']); $nModified = filemtime($this->cache_filename); if ($this->config_nooffsitelink_enabled && @$_SERVER['HTTP_REFERER'] && !in_array(@$parsed_url['host'], $this->config_nooffsitelink_valid_domains)) { $this->DebugMessage('Would have used cached (image/'.$this->thumbnailFormat.') file "'.$this->cache_filename.'" (Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT), but skipping because $_SERVER[HTTP_REFERER] ('.@$_SERVER['HTTP_REFERER'].') is not in $this->config_nooffsitelink_valid_domains ('.implode(';', $this->config_nooffsitelink_valid_domains).')', __FILE__, __LINE__); } elseif ($this->phpThumbDebug) { $this->DebugTimingMessage('skipped using cached image', __FILE__, __LINE__); $this->DebugMessage('Would have used cached file, but skipping due to phpThumbDebug', __FILE__, __LINE__); $this->DebugMessage('* Would have sent headers (1): Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT', __FILE__, __LINE__); $getimagesize = @GetImageSize($this->cache_filename); if ($getimagesize) { $this->DebugMessage('* Would have sent headers (2): Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2]), __FILE__, __LINE__); } if (ereg('^'.preg_quote($nice_docroot).'(.*)$', $nice_cachefile, $matches)) { $this->DebugMessage('* Would have sent headers (3): Location: '.dirname($matches[1]).'/'.urlencode(basename($matches[1])), __FILE__, __LINE__); } else { $this->DebugMessage('* Would have sent data: readfile('.$this->cache_filename.')', __FILE__, __LINE__); } } else { if (headers_sent()) { $this->ErrorImage('Headers already sent ('.basename(__FILE__).' line '.__LINE__.')'); exit; } $this->SendSaveAsFileHeaderIfNeeded(); header('Last-Modified: '.gmdate('D, d M Y H:i:s', $nModified).' GMT'); if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] && ($nModified == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) && @$_SERVER['SERVER_PROTOCOL']) { header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified'); exit; } $getimagesize = @GetImageSize($this->cache_filename); if ($getimagesize) { header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2])); } elseif (eregi('\.ico$', $this->cache_filename)) { header('Content-Type: image/x-icon'); } if (!$this->config_cache_force_passthru && ereg('^'.preg_quote($nice_docroot).'(.*)$', $nice_cachefile, $matches)) { header('Location: '.dirname($matches[1]).'/'.urlencode(basename($matches[1]))); } else { @readfile($this->cache_filename); } exit; } return true; }
function OutputThumbnail() { $this->purgeTempFiles(); if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) { $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__); return false; } if (headers_sent()) { return $this->ErrorImage('OutputThumbnail() failed - headers already sent'); exit; } $downloadfilename = phpthumb_functions::SanitizeFilename(is_string($this->sia) ? $this->sia : ($this->down ? $this->down : 'phpThumb_generated_thumbnail' . '.' . $this->thumbnailFormat)); $this->DebugMessage('Content-Disposition header filename set to "' . $downloadfilename . '"', __FILE__, __LINE__); if ($downloadfilename) { header('Content-Disposition: ' . ($this->down ? 'attachment' : 'inline') . '; filename="' . $downloadfilename . '"'); } else { $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__); } if ($this->useRawIMoutput) { header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $this->IMresizedData; } else { $this->DebugMessage('ImageInterlace($this->gdimg_output, ' . intval($this->config_output_interlace) . ')', __FILE__, __LINE__); ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); switch ($this->thumbnailFormat) { case 'jpeg': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output); break; case 'bmp': if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__); return false; } $phpthumb_bmp = new phpthumb_bmp(); if (is_object($phpthumb_bmp)) { $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output); unset($phpthumb_bmp); if (!$bmp_data) { $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $bmp_data; } else { $this->DebugMessage('new phpthumb_bmp() failed', __FILE__, __LINE__); return false; } break; case 'ico': if (!@(include_once dirname(__FILE__) . '/phpthumb.ico.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__); return false; } $phpthumb_ico = new phpthumb_ico(); if (is_object($phpthumb_ico)) { $arrayOfOutputImages = array($this->gdimg_output); $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages); unset($phpthumb_ico); if (!$ico_data) { $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $ico_data; } else { $this->DebugMessage('new phpthumb_ico() failed', __FILE__, __LINE__); return false; } break; default: $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__); return false; break; } } return true; }
} //////////////////////////////////////////////////////////////// // check to see if file can be output from source with no processing or caching $CanPassThroughDirectly = true; $FilenameParameters = array('h', 'w', 'sx', 'sy', 'sw', 'sh', 'bw', 'brx', 'bry', 'bg', 'bgt', 'bc', 'usa', 'usr', 'ust', 'wmf', 'wmp', 'wmm', 'wma', 'xto', 'ra', 'ar', 'iar', 'maxb'); foreach ($FilenameParameters as $key) { if (isset($_REQUEST[$key])) { $CanPassThroughDirectly = false; break; } } if ($CanPassThroughDirectly && !empty($_REQUEST['src'])) { // no parameters set, passthru $SourceFilename = $phpThumb->ResolveFilenameToAbsolute($_REQUEST['src']); if ($getimagesize = @GetImageSize($SourceFilename)) { header('Content-type: ' . phpthumb_functions::ImageTypeToMIMEtype($getimagesize[2])); @readfile($SourceFilename); exit; } } // check to see if file already exists in cache, and output it with no processing if it does if (!empty($phpThumb->config_cache_directory) && empty($_REQUEST['phpThumbDebug'])) { $cache_filename = $phpThumb->GenerateCachedFilename(); if (is_file($cache_filename)) { header('Content-type: image/' . $phpThumb->thumbnailFormat); @readfile($cache_filename); exit; } } //////////////////////////////////////////////////////////////// // You may want to pull data from a database rather than a physical file
function OutputThumbnail() { if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) { $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__); return false; } if (headers_sent()) { return $this->ErrorImage('OutputThumbnail() failed - headers already sent'); exit; } if ($this->down) { $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down); if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) { $downloadfilename = trim($downloadfilename, '.'); } if ($downloadfilename != $this->down) { $this->DebugMessage('renaming output file for "down" from "' . $this->down . '" to "' . $downloadfilename . '"', __FILE__, __LINE__); } if ($downloadfilename) { header('Content-Disposition: attachment; filename="' . $downloadfilename . '"'); } else { $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__); } } if ($this->useRawIMoutput) { header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $this->IMresizedData; } else { $this->DebugMessage('ImageInterlace($this->gdimg_output, ' . intval($this->config_output_interlace) . ')', __FILE__, __LINE__); ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); switch ($this->thumbnailFormat) { case 'jpeg': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output); break; case 'bmp': if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__); return false; } $phpthumb_bmp = new phpthumb_bmp(); if (is_object($phpthumb_bmp)) { $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output); unset($phpthumb_bmp); if (!$bmp_data) { $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $bmp_data; } else { $this->DebugMessage('new phpthumb_bmp() failed', __FILE__, __LINE__); return false; } break; case 'ico': if (!@(include_once dirname(__FILE__) . '/phpthumb.ico.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__); return false; } $phpthumb_ico = new phpthumb_ico(); if (is_object($phpthumb_ico)) { $arrayOfOutputImages = array($this->gdimg_output); $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages); unset($phpthumb_ico); if (!$ico_data) { $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $ico_data; } else { $this->DebugMessage('new phpthumb_ico() failed', __FILE__, __LINE__); return false; } break; default: $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__); return false; break; } } return true; }
function ExtractEXIFgetImageSize() { if (is_resource($this->gdimg_source)) { $this->source_width = ImageSX($this->gdimg_source); $this->source_height = ImageSY($this->gdimg_source); } elseif ($this->rawImageData && !$this->sourceFilename) { $this->DebugMessage('bypassing EXIF and GetImageSize sections because $this->rawImageData is set and $this->sourceFilename is not', __FILE__, __LINE__); } elseif ($this->getimagesizeinfo = @GetImageSize($this->sourceFilename)) { $this->source_width = $this->getimagesizeinfo[0]; $this->source_height = $this->getimagesizeinfo[1]; if (function_exists('exif_thumbnail') && $this->getimagesizeinfo[2] == 2) { // Extract EXIF info from JPEGs $this->exif_thumbnail_width = ''; $this->exif_thumbnail_height = ''; $this->exif_thumbnail_type = ''; // The parameters width, height and imagetype are available since PHP v4.3.0 if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=')) { $this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename, $this->exif_thumbnail_width, $this->exif_thumbnail_height, $this->exif_thumbnail_type); } else { // older versions of exif_thumbnail output an error message but NOT return false on failure ob_start(); $this->exif_thumbnail_data = exif_thumbnail($this->sourceFilename); $exit_thumbnail_error = ob_get_contents(); ob_end_clean(); if (empty($exit_thumbnail_error) && !empty($this->exif_thumbnail_data)) { if ($gdimg_exif_temp = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false)) { $this->exif_thumbnail_width = ImageSX($gdimg_exif_temp); $this->exif_thumbnail_height = ImageSY($gdimg_exif_temp); $this->exif_thumbnail_type = 2; // (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned unset($gdimg_exif_temp); } else { return $this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in ' . __FILE__ . ' on line ' . __LINE__); } } } } elseif (!function_exists('exif_thumbnail')) { $this->DebugMessage('exif_thumbnail() does not exist, cannot extract EXIF thumbnail', __FILE__, __LINE__); } // see if EXIF thumbnail can be used directly with no processing if (!empty($this->exif_thumbnail_data)) { while (true) { if (empty($this->xto)) { if (isset($this->w) && $this->w != $this->exif_thumbnail_width) { break; } if (isset($this->h) && $this->h != $this->exif_thumbnail_height) { break; } $CannotBeSetParameters = array('sx', 'sy', 'sh', 'sw', 'far', 'bg', 'bc', 'fltr', 'phpThumbDebug'); foreach ($CannotBeSetParameters as $parameter) { if (!empty($this->{$parameter})) { break 2; } } } // EXIF thumbnail can be used directly for these parameters - write cached file $ImageTypesLookup = array(2 => 'jpeg'); // EXIF thumbnails are (currently?) only availble from JPEG source images if (is_dir($this->config_cache_directory) && is_writable($this->config_cache_directory) && isset($ImageTypesLookup[$this->exif_thumbnail_type])) { if ($fp_cached = @fopen($this->cache_filename, 'wb')) { fwrite($fp_cached, $this->exif_thumbnail_data); fclose($fp_cached); } else { $this->DebugMessage('failed to fopen $this->cache_filename (' . $this->cache_filename . ')', __FILE__, __LINE__); } } else { $this->DebugMessage('!is_dir($this->config_cache_directory), or !is_writable($this->config_cache_directory) (' . $this->cache_filename . '); or !isset($ImageTypesLookup[' . $this->exif_thumbnail_type . '])', __FILE__, __LINE__); } if ($mime_type = phpthumb_functions::ImageTypeToMIMEtype($this->exif_thumbnail_type)) { header('Content-type: ' . $mime_type); echo $this->exif_thumbnail_data; exit; } else { return $this->ErrorImage('phpthumb_functions::ImageTypeToMIMEtype(' . $this->exif_thumbnail_type . ') failed in ' . __FILE__ . ' on line ' . __LINE__); } break; } } if ($this->config_max_source_pixels > 0 && $this->source_width * $this->source_height > $this->config_max_source_pixels) { // Source image is larger than would fit in available PHP memory. // If ImageMagick is installed, use it to generate the thumbnail. // Else, if an EXIF thumbnail is available, use that as the source image. // Otherwise, no choice but to fail with an error message $this->DebugMessage('image is ' . $this->source_width . 'x' . $this->source_height . ' and therefore contains more pixels (' . $this->source_width * $this->source_height . ') than $this->config_max_source_pixels setting (' . $this->config_max_source_pixels . ')', __FILE__, __LINE__); if ($this->ImageMagickThumbnailToGD()) { // excellent, we have a thumbnailed source image } elseif (!empty($this->exif_thumbnail_data)) { $this->DebugMessage('ImageMagickThumbnailToGD() failed, but $this->exif_thumbnail_data is usable', __FILE__, __LINE__); // EXIF thumbnail exists, and will be use as source image $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data); $this->source_width = $this->exif_thumbnail_width; $this->source_height = $this->exif_thumbnail_height; // override allow-enlarging setting if EXIF thumbnail is the only source available // otherwise thumbnails larger than the EXIF thumbnail will be created at EXIF size $this->config_output_allow_enlarging = true; } else { return $this->ErrorImage('Source image is (' . $this->source_width . 'x' . $this->source_height . ') which equals ' . sprintf('%1.1f', $this->source_width * $this->source_height) . ' megapixels, which is more than the allowed ' . sprintf('%1.1f', $this->config_max_source_pixels / 1000000) . ' megapixels -- insufficient memory.' . "\n" . 'EXIF thumbnail unavailable.'); } } } else { $this->DebugMessage('GetImageSize("' . $this->sourceFilename . '") failed', __FILE__, __LINE__); } return true; }
if (file_exists($cacheKey)) { $modx->log(modX::LOG_LEVEL_DEBUG, '[phpThumbOf] Using cached file found for thumb: ' . $cacheKey); $output = str_replace(' ', '%20', $cacheUrl); } else { /* actually make the thumbnail */ //return $cacheKey; if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! if ($phpThumb->RenderToFile($cacheKey)) { $output = str_replace(' ', '%20', $cacheUrl); } else { $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not cache thumb "' . $src . '" to file at: ' . $cacheKey . ' - Debug: ' . print_r($phpThumb->debugmessages, true)); } } else { $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not generate thumbnail: ' . $src . ' - Debug: ' . print_r($phpThumb->debugmessages, true)); } } if (!headers_sent()) { $headers = $modx->request->getHeaders(); $mtime = filemtime($cacheKey); if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $mtime) { // cache is good, send 304 header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT', true, 304); exit; } header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT', true, 200); $phpThumb->setOutputFormat(); header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($phpThumb->thumbnailFormat)); header('Content-Disposition: inline; filename="' . basename($src) . '"'); } return file_get_contents($cacheKey);