// // available at http://phpthumb.sourceforge.net // // and/or https://github.com/JamesHeinrich/phpThumb // ////////////////////////////////////////////////////////////// /// // // phpThumb.demo.check.php // // James Heinrich // // // // Configuration analyzer for phpThumb settings and server // // settings that may affect phpThumb performance // // Live demo is at http://phpthumb.sourceforge.net/demo/ // // // ////////////////////////////////////////////////////////////// die('For security reasons, this demo is disabled by default. Please comment out line '.__LINE__.' in '.basename(__FILE__)); $ServerInfo['gd_string'] = 'unknown'; $ServerInfo['gd_numeric'] = 0; //ob_start(); if (!include_once '../phpthumb.functions.php' ) { ob_end_flush(); die('failed to include_once("../phpthumb.functions.php")'); } if (!include_once '../phpthumb.class.php' ) { //ob_end_flush(); die('failed to include_once("../phpthumb.class.php")'); } //ob_end_clean(); $phpThumb = new phpThumb(); if (file_exists('../phpThumb.config.php') && include_once '../phpThumb.config.php' ) { foreach ($PHPTHUMB_CONFIG as $key => $value) { $phpThumb->setParameter('config_'.$key, $value); } } else { echo '
Error reading ../phpThumb.config.php

'; } $ServerInfo['gd_string'] = phpthumb_functions::gd_version(true); $ServerInfo['gd_numeric'] = phpthumb_functions::gd_version(false); $ServerInfo['im_version'] = $phpThumb->ImageMagickVersion(); $gd_info = gd_info(); ?> phpThumb configuration analyzer This demo analyzes your settings (phpThumb.config.php and server/PHP) for phpThumb().

<-- bad . . . . . good -->
                                       
phpthumb_functions::SafeURLread('http://phpthumb.sourceforge.net/?latestversion=1', $dummy), 'this' => $phpThumb->phpthumb_version, ); foreach ($versions['raw'] as $key => $value) { preg_match('#^([0-9\\.]+)\\-?(([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2}))?#i', $value, $matches); @list($huge, $major, $minor) = @explode('.', @$matches[1]); @list($year, $month, $day, $hour, $min) = @$matches[3]; $versions['base'][$key] = $matches[1]; $versions['huge'][$key] = $huge; $versions['major'][$key] = $major; $versions['minor'][$key] = $minor; $versions['stamp'][$key] = $matches[2]; $versions['year'][$key] = $year; $versions['month'][$key] = $month; $versions['day'][$key] = $day; $versions['hour'][$key] = $hour; $versions['min'][$key] = $min; $versions['date'][$key] = @mktime($hour, $min, 0, $month, $day, $year); } $downloadlatest = 'Download the latest version from https://github.com/JamesHeinrich/phpThumb/'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $password_complexity = phpthumb_functions::PasswordStrength($PHPTHUMB_CONFIG['high_security_password']); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $IMreleaseDate = 0; if (preg_match('# ([0-9]{2})/([0-9]{2})/([0-9]{2}) #', $ServerInfo['im_version'], $matches)) { list($dummy, $m, $d, $y) = $matches; if ($y < 70) { $y += 2000; } elseif ($y < 100) { $y += 1900; } $IMreleaseDate = mktime(12, 0, 0, $m, $d, $y); } elseif (preg_match('# ([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) #', $ServerInfo['im_version'], $matches)) { list($dummy, $y, $m, $d) = $matches; $IMreleaseDate = mktime(12, 0, 0, $m, $d, $y); } $IMversionAge = time() - $IMreleaseDate; echo ''; echo ''; if ($ServerInfo['im_version']) { $GDfeatures['red'] = array('help', 'thumbnail', 'resize', 'crop', 'repage', 'coalesce', 'gravity', 'background', 'interlace', 'flatten', 'border', 'bordercolor', 'dither', 'quality'); $GDfeatures['orange'] = array('version', 'blur', 'colorize', 'colors', 'colorspace', 'contrast', 'contrast-stretch', 'edge', 'emboss', 'fill', 'flip', 'flop', 'gamma', array('gaussian','gaussian-blur'), 'level', 'modulate', 'monochrome', 'negate', 'normalize', 'rotate', 'sepia-tone', 'threshold', 'unsharp'); echo ''; } else { echo ''; } echo ''; echo ''; if ($ServerInfo['im_version']) { echo ''; } else { echo ''; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $FunctionsExist = array( 'imagerotate' => array('orange', 'required for "ra" and "ar" filters.'), 'exif_read_data' => array('yellow', 'required for "ar" filter.'), 'exif_thumbnail' => array('yellow', 'required to extract EXIF thumbnails.'), 'memory_get_usage' => array('lightgreen', 'mostly used for troubleshooting.'), 'version_compare' => array('darkgreen', 'available in PHP v4.1.0+, internal workaround available'), 'file_get_contents' => array('darkgreen', 'available in PHP v4.3.0+, internal workaround available'), 'file_put_contents' => array('darkgreen', 'available in PHP v5.0.0+, internal workaround available'), 'is_executable' => array('yellow', 'available in PHP3, except only PHP5 for Windows. poor internal workaround available'), 'gd_info' => array('olive', 'available in PHP v4.3.0+ (with bundled GD2), internal workaround available'), 'imagetypes' => array('red', 'required for GD image output.'), 'imagecreatefromjpeg' => array('orange', 'required for JPEG source images using GD.'), 'imagecreatefromgif' => array('yellow', 'useful for GIF source images using GD.'), 'imagecreatefrompng' => array('orange', 'required for PNG source images using GD and other source image formats using ImageMagick.'), 'imagecreatefromwbmp' => array('yellow', 'required for WBMP source images using GD.'), 'imagecreatefromstring' => array('orange', 'required for HTTP and non-file image sources.'), 'imagecreatetruecolor' => array('orange', 'required for all non-ImageMagick filters.'), 'imageistruecolor' => array('olive', 'available in PHP v4.3.2+ with GD v2.0.1+'), 'imagefilter' => array('yellow', 'PHP5 only. Required for some filters (but most can use ImageMagick instead)'), 'imageautocrop' => array('yellow', 'PHP v5.5.0+, required for "ica" filter'), ); foreach ($FunctionsExist as $function => $details) { list($color, $description) = $details; echo ''; } echo ''; echo ''; $SettingFeatures = array( 'magic_quotes_runtime' => array('red', 'lime', 'This setting is evil. Turn it off.'), 'magic_quotes_gpc' => array('yellow', 'lime', 'This setting is bad. Turn it off, if possible. phpThumb will attempt to work around it if it is enabled.'), 'safe_mode' => array('orange', 'lime', 'Best if off. Calls to ImageMagick will be disabled if safe_mode is set to prevent writing temp files (limiting max image resolution, no animated GIF resize). Raw image data sources (e.g. from MySQL database) may not work. Temp files may be disabled. Features will be limited. If disabled in Master but enabled in Local, edit httpd.conf and set (php_admin_value safe_mode "Off") between tags'), 'allow_url_fopen' => array('lime', 'yellow', 'Best if on. HTTP source images will be unavailable if disabled and CURL is unavailable.'), ); foreach ($SettingFeatures as $feature => $FeaturesDetails) { list($color_true, $color_false, $reason) = $FeaturesDetails; echo ''; echo ''; echo ''; echo ''; } $MissingFunctionSeverity = array( 'shell_exec' => 'red', 'system' => 'red', 'passthru' => 'red', 'exec' => 'red', 'curl_exec' => 'orange', ); $DisabledFunctions[0] = explode(',', @get_cfg_var('disable_functions')); $DisabledFunctions[1] = explode(',', @ini_get('disable_functions')); echo ''; for ($i = 0; $i <= 1; $i++) { foreach ($DisabledFunctions[$i] as $key => $value) { if (!empty($MissingFunctionSeverity[$value])) { $DisabledFunctions[$i][$key] = ''.$value.''; } } $disabled_functions = implode(', ', $DisabledFunctions[$i]); echo ''; } echo ''; echo ''; echo ''; echo '
SettingValueComments
Latest phpThumb version:'.$versions['raw']['latest'].''.$downloadlatest.'
This phpThumb version:info@silisoftware.com'; } elseif (($versions['base']['latest'] == $versions['base']['this']) && ($versions['stamp']['this'] > $versions['stamp']['latest'])) { // new than latest, must be beta version echo 'lightblue'; $message = 'You must be using a pre-release beta version. Please report bugs to info@silisoftware.com'; } elseif ($versions['base']['latest'] == $versions['base']['this']) { // latest version echo 'lime'; $message = 'You are using the latest released version.'; } elseif ($versions['huge']['latest'].$versions['major']['latest'] == $versions['huge']['this'].$versions['major']['this']) { echo 'olive'; $message = 'One (or more) minor version(s) have been released since this version.
'.$downloadlatest; } elseif ((float) ($versions[ 'huge'][ 'latest'].str_pad($versions[ 'major'][ 'latest'], 2, '0', STR_PAD_LEFT)) < (float) ($versions[ 'huge'][ 'this'].str_pad($t_major, 2, '0', STR_PAD_LEFT))) { echo 'yellow'; $message = 'One (or more) major version(s) have been released since this version, you really should upgrade.
'.$downloadlatest; } else { echo 'orange'; $message = 'Fundamental changes have been made since this version.
'.$downloadlatest; } echo ';">'.$phpThumb->phpthumb_version; echo '
'.$message.'.
phpThumb.config.php:"phpThumb.config.php" version does not match phpThumb version. Please be sure to use the config file from the phpThumb distribution (copy any customized settings to the .default file, then rename "phpThumb.config.php.default" to "phpThumb.config.php")'; } else { echo 'lime;">"phpThumb.config.php" exists and "phpThumb.config.php.default" does not'; } } elseif (file_exists('../phpThumb.config.php') && file_exists('../phpThumb.config.php.default')) { echo 'yellow;">"phpThumb.config.php" and "phpThumb.config.php.default" both exist'; } elseif (!file_exists('../phpThumb.config.php') && file_exists('../phpThumb.config.php.default')) { echo 'red;">rename "phpThumb.config.php.default" to "phpThumb.config.php"'; } else { echo 'red;">"phpThumb.config.php" not found'; } echo '"phpThumb.config.php.default" that comes in the distribution must be renamed to "phpThumb.config.php" before phpThumb.php can be used. Avoid having both files present to minimize confusion.
phpThumb.config.php
[disable_debug]
'.($PHPTHUMB_CONFIG['disable_debug'] ? 'true' : 'false').'DO NOT DISABLE THIS ON ANY PUBLIC-ACCESSIBLE SERVER. Prevents phpThumb from displaying any information about your system. If true, phpThumbDebug and error messages will be disabled. If set to false (debug messages enabled) then debug mode will be FORCED -- ONLY debug output will be presented, no actual thumbnail (to avoid accidentally leaving debug mode enabled on a production server).
phpThumb.config.php
[high_security_enabled]
'.($PHPTHUMB_CONFIG['high_security_enabled'] ? 'true' : 'false').'DO NOT DISABLE THIS ON ANY PUBLIC-ACCESSIBLE SERVER. If disabled, your server is more vulnerable to hacking attempts, both on your server and via your server to other servers. When enabled, requires "high_security_password" set to be set and requires the use of phpThumbURL() function (at the bottom of phpThumb.config.php) to generate hashed URLs.
phpThumb.config.php
[high_security_password]
'.(($password_complexity >= 20) ? 'sufficiently complex' : ((strlen($PHPTHUMB_CONFIG['high_security_password']) > 0) ? 'not complex enough' : 'not set')).'DO NOT DISABLE THIS ON ANY PUBLIC-ACCESSIBLE SERVER. If disabled, your server is more vulnerable to hacking attempts, both on your server and via your server to other servers. When enabled, requires "high_security_password" set to be set and requires the use of phpThumbURL() function (at the bottom of phpThumb.config.php) to generate hashed URLs.
cache directory:'; $orig_config_cache_directory = $phpThumb->config_cache_directory; $phpThumb->setCacheDirectory(); echo '
exists' : 'red;">does NOT exist').'
'; echo '
readable' : 'red;">NOT readable' ).'
'; echo '
writable' : 'red;">NOT writable' ).'
'; echo '
Original: "'.htmlspecialchars($orig_config_cache_directory).'"
Resolved: "'.htmlspecialchars($phpThumb->config_cache_directory).'"
Must exist and be both readable and writable by PHP.
cache write test:'; $phpThumb->rawImageData = 'phpThumb.demo.check.php_cachetest'; $phpThumb->SetCacheFilename(); echo '
'.htmlspecialchars($phpThumb->cache_filename ? implode(' / ', preg_split('#[/\\\\]#', $phpThumb->cache_filename)) : 'NO CACHE FILENAME RESOLVED').'
'; echo '
directory '.(is_dir(dirname($phpThumb->cache_filename)) ? 'exists' : 'does NOT exist').' (before EnsureDirectoryExists())
'; phpthumb_functions::EnsureDirectoryExists(dirname($phpThumb->cache_filename)); echo '
directory exists' : 'red;">directory does NOT exist').' (after EnsureDirectoryExists())
'; if ($fp = @fopen($phpThumb->cache_filename, 'wb')) { fwrite($fp, 'this is a test from '.__FILE__); fclose($fp); echo '
write test succeeded
'; $old_perms = substr(sprintf('%o', fileperms($phpThumb->cache_filename)), -4); @chmod($phpThumb->cache_filename, 0644); clearstatcache(); $new_perms = substr(sprintf('%o', fileperms($phpThumb->cache_filename)), -4); echo '
chmod($phpThumb->cache_filename, 0644) from "'.htmlspecialchars($old_perms).'" resulted in permissions "'.htmlspecialchars($new_perms).'"
'; if (@unlink($phpThumb->cache_filename)) { echo '
delete test succeeded
'; } else { echo '
delete test FAILED
'; } $phpThumb->CleanUpCacheDirectory(); } else { echo '
write test FAILED
'; } //echo '
Original: "'.htmlspecialchars($orig_config_cache_directory).'"
Resolved: "'.htmlspecialchars($phpThumb->config_cache_directory).'"
Must exist and be both readable and writable by PHP.
Created and deletes a sample cache file to see if you actually have create/delete permission.
If Safe Mode is enabled this is often broken.
temp directory:'; $orig_config_temp_directory = $phpThumb->config_temp_directory; echo $phpThumb->phpThumb_tempnam(); echo '
exists' : 'red;">does NOT exist').'
'; echo '
readable' : 'red;">NOT readable' ).'
'; echo '
writable' : 'red;">NOT writable' ).'
'; echo '
Original: "'.htmlspecialchars($orig_config_temp_directory).'"
Resolved: "'.htmlspecialchars($phpThumb->config_temp_directory).'"
Must exist and be both readable and writable by PHP.
PHP version:'. PHP_VERSION; echo 'PHP5 is ideal (support for numerous built-in filters which are much faster than my code).
PHP v4.4.2 contains a bug in fopen over HTTP (phpThumb has a workaround)
PHP v4.3.2+ supports imagesavealpha which is required for proper PNG/ICO output.
imagerotate requires PHP v4.3.0+ (but buggy before v4.3.3).
EXIF thumbnail extraction requires PHP v4.2.0+.
Most things will work back to PHP v4.1.0, and mostly (perhaps buggy) back to v4.0.6, but no guarantees for any version older than that.
GD version:'.(!empty($ServerInfo['gd_string']) ? $ServerInfo['gd_string'] : 'n/a'); echo 'GD2-bundled version is ideal.
GD2 (non-bundled) is second choice, but there are a number of bugs in the non-bundled version. imagerotate is only available in the bundled version of GD2.
GD1 will also (mostly) work, at much-reduced image quality and several features disabled. phpThumb can perform most operations with ImageMagick only, even if GD is not available.
ImageMagick version:'; echo '
'.htmlspecialchars($phpThumb->config_imagemagick_path); echo ' ['. (int) (@file_exists($phpThumb->config_imagemagick_path)) .'] '; echo ' ['. (int) $phpThumb->file_exists_ignoreopenbasedir($phpThumb->config_imagemagick_path) .'] '; echo ' ['. (int) (@is_file($phpThumb->config_imagemagick_path)) .'] '; echo ' ['. (int) (@is_readable($phpThumb->config_imagemagick_path)) .'] '; echo ' ['. (int) (@is_executable($phpThumb->config_imagemagick_path)) .'] '; echo '
'; echo '
'.htmlspecialchars($phpThumb->ImageMagickCommandlineBase()).'
'; echo ($ServerInfo['im_version'] ?: 'n/a'); echo ($IMreleaseDate ? '

This version of ImageMagick is '.NiceTimeFormatting($IMversionAge).' old
(see www.imagemagick.org for new versions)' : ''); echo '
ImageMagick is faster than GD, can process larger images without PHP memory_limit issues, can resize animated GIFs. phpThumb can perform most operations with ImageMagick only, even if GD is not available.
ImageMagick features:|'; foreach ($GDfeatures as $missingcolor => $features) { foreach ($features as $dummy => $feature) { $foundOneThatWorks = false; if (is_array($feature)) { // sometimes feature names change, e.g. "gaussian" -> "gaussian-blur". They won't both exist in the same version of ImageMagick, but as long as one of them does then the feature will work foreach ($feature as $alternate_feature_name) { if ($phpThumb->ImageMagickSwitchAvailable($alternate_feature_name)) { $foundOneThatWorks = true; $feature = $alternate_feature_name; break; } echo '| '.htmlspecialchars($alternate_feature_name).' |'; } } else { $foundOneThatWorks = $phpThumb->ImageMagickSwitchAvailable($feature); echo '| '.htmlspecialchars($feature).' |'; } } } echo '|ImageMagick not foundAll of these parameters may be called by phpThumb, depending on parameters used. Green means the feature is available; red means a critical feature is missing; orange means an optional filter/feature is missing.
ImageMagick formats:
'.htmlspecialchars($phpThumb->ImageMagickFormatsList()).'
ImageMagick not foundImageMagick can only read/write formats as listed here. You may need to recompile ImageMagick if you need to use a format not listed
GD features:'; $GDfeatures['red'] = array('JPEG Support', 'JPG Support', 'PNG Support'); // older versions would report "JPG Support", newer versions report "JPEG Support" $GDfeatures['orange'] = array('GIF Read Support', 'GIF Create Support', 'FreeType Support'); foreach ($GDfeatures as $missingcolor => $features) { foreach ($features as $dummy => $feature) { if (isset($gd_info[$feature])) { echo '
'.htmlspecialchars($feature).'
'; } } } echo '
PNG support is required for watermarks, overlays, calls to ImageMagick and other internal operations.
JPG support is obviously quite useful, but ImageMagick can substitute
GIF read support can be bypassed with ImageMagick and/or internal GIF routines.
GIF create support can be bypassed with ImageMagick (if no filters are applied)
FreeType support is needed for TTF overlays.
GD extension "EXIF"'.(extension_loaded('exif') ? 'TRUE' : 'FALSE'); echo 'EXIF extension required for auto-rotate images. Also required to extract EXIF thumbnail to use as source if source image is too large for PHP memory_limit and ImageMagick is unavailable.
php_sapi_name()'.htmlspecialchars($php_sapi_name).'SAPI mode preferred to CGI mode. FCGI mode has unconfirmed strange behavior (notably more than one space in "wmt" filter text causes errors). If not working in "apache" (SAPI) mode, apache_lookup_uri() will not work.
Server Software'.$server_software.'Apache v1.x has the fewest compatibility problems. IIS has numerous annoyances. Apache v2.x is broken when lookup up /~user/filename.jpg style relative filenames using apache_lookup_uri().
curl_version:'.$curl_version.'Best if available. HTTP source images will be unavailable if CURL unavailable and allow_url_fopen is also disabled.
 
function_exists:ValueComments
'.$function.'TRUE'; } else { echo $color.';">FALSE'; } echo ''.htmlspecialchars($description).'
 
SettingMaster ValueLocal ValueComments
'.$feature.':'.$phpThumb->phpThumbDebugVarDump((bool) @get_cfg_var($feature)).''.$phpThumb->phpThumbDebugVarDump((bool) preg_match('#(1|ON)#i', ini_get($feature))).''.htmlspecialchars($reason).'
disable_functions:'.htmlspecialchars($disabled_functions).'Best if nothing disabled. Calls to ImageMagick will be prevented if exec+system+shell_exec+passthru are disabled.
memory_limit:'.($memory_limit ?: 'unlimited').''.($memory_limit ?: 'unlimited').'The higher the better. Divide by 5 to get maximum megapixels of source image that can be thumbnailed (without ImageMagick).'.($memory_limit ? ' Your setting ('.$memory_limit.') allows images up to approximately '.number_format($memory_limit_bytes / (5*1024*1024), 1).' megapixels' : '').'
'; function NiceTimeFormatting($seconds, $precision=1, $returnparts=false) { $sign = (($seconds < 0) ? -1 : 1); $seconds = abs($seconds); do { if ($seconds < 100) { $value = number_format($seconds, 0); $unit = 'second'.(($seconds > 1) ? 's' : ''); break; } $minutes = $seconds / 60; if ($minutes < 60) { $value = number_format($minutes, $precision); $unit = 'minutes'; break; } $hours = $seconds / 3600; if ($hours < 24) { $value = number_format($hours, $precision); $unit = 'hours'; break; } $days = $seconds / 86400; if ($days < 60) { $value = number_format($days, $precision); $unit = 'days'; break; } $months = $seconds / (30 * 86400); if ($months < 12) { $value = number_format($months, $precision); $unit = 'months'; break; } $years = $seconds / (365 * 86400); if (true) { $value = number_format($years, $precision); $unit = 'years'; break; } } while (false); $value *= $sign; if ($returnparts) { return array($value, $unit); } return $value.' '.$unit; } ?>