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);