Location: PHPKode > projects > Open Media Collectors Database > docs/test/test_phpthumb.php
<?php
//////////////////////////////////////////////////////////////
///  phpThumb() by James Heinrich <hide@address.com>   //
//        available at http://phpthumb.sourceforge.net     ///
//////////////////////////////////////////////////////////////
///                                                         //
// phpThumb.demo.check.php                                  //
// James Heinrich <hide@address.com>                   //
//                                                          //
// Configuration analyzer for phpThumb settings and server  //
// settings that may affect phpThumb performance            //
// Live demo is at http://phpthumb.sourceforge.net/demo/    //
//                                                          //
//////////////////////////////////////////////////////////////

$ServerInfo['gd_string']  = 'unknown';
$ServerInfo['gd_numeric'] = 0;

if (!include_once('../../functions/phpthumb/phpthumb.class.php')) {
	die('failed to include_once("../phpthumb.class.php")');
}

$phpThumb = new phpThumb();

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

?>

<html>
<head>
	<title>phpThumb configuration analyzer</title>
	<link rel="stylesheet" type="text/css" href="/style.css" title="style sheet">
</head>
<body bgcolor="#CCCCCC">

This page analyzes your settings (server/PHP) for <a href="http://phpthumb.sourceforge.net"><b>phpThumb()</a> package embedded in OpenDb</b><br>
<br>
<p>
<table border="1">
	<tr><th colspan="8">&lt;-- bad . . . . . good --&gt;</th></tr>
	<tr>
		<td bgcolor="red">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="orange">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="yellow">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="olive">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="darkgreen">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="green">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="lightgreen">&nbsp;&nbsp;&nbsp;&nbsp;</td>
		<td bgcolor="lime">&nbsp;&nbsp;&nbsp;&nbsp;</td>
	</tr>
</table>
</p>

<table border="1" cellspacing="0" cellpadding="2">
<tr bgcolor="#EEEEEE"><th>Setting</th><th colspan="2">Value</th><th>Comments</th></tr>
<?php

echo '<tr><th>PHP version:</th><th colspan="2" bgcolor="';
if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=')) {
	echo 'lime';
} elseif (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.3', '>=')) {
	echo 'lightgreen';
} elseif (phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0', '>=')) {
	echo 'green';
} elseif (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
	echo 'yellow';
} elseif (phpthumb_functions::version_compare_replacement(phpversion(), '4.0.6', '>=')) {
	echo 'orange';
} else {
	echo 'red';
}
echo '">'.phpversion();
echo '</th><td>PHP5 is ideal (support for numerous built-in filters which are much faster than my code).<br>PHP v4.3.2+ supports ImageSaveAlpha which is required for proper PNG/ICO output.<br>ImageRotate requires PHP v4.3.0+ (but buggy before v4.3.3).<br>EXIF thumbnail extraction requires PHP v4.2.0+.<br>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.</td></tr>';

echo '<tr><th>GD version:</th><th colspan="2" bgcolor="';
if ($ServerInfo['gd_numeric'] >= 2) {
	if (eregi('bundled', @$ServerInfo['gd_string'])) {
		echo 'lime';
	} else {
		echo 'yellow';
	}
} elseif ($ServerInfo['im_version']) {
	echo 'orange';
} else {
	echo 'red';
}
echo '">'.@$ServerInfo['gd_string'];
echo '</th><td>GD2-bundled version is ideal.<br>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.<br>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.</td></tr>';

echo '<tr><th>ImageMagick version:</th><th colspan="2" bgcolor="';
if ($ServerInfo['im_version']) {
	echo 'lime';
} elseif (@$ServerInfo['gd_string']) {
	echo 'orange';
} else {
	echo 'red';
}
echo '">"'.$phpThumb->ImageMagickCommandlineBase().'"<br>'.($ServerInfo['im_version'] ? $ServerInfo['im_version'] : 'n/a');
echo '</th><td>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.</td></tr>';


echo '<tr><th>ImageMagick features:</th><th colspan="2">';
$GDfeatures['red']    = array('version', 'help', 'thumbnail', 'crop', 'repage', 'coalesce', 'gravity', 'background', 'interlace', 'flatten', 'border', 'bordercolor', 'dither', 'quality');
$GDfeatures['orange'] = array('blur', 'colorize', 'colors', 'colorspace', 'contrast', 'edge', 'emboss', 'fill', 'flip', 'flop', 'gamma', 'gaussian', 'level', 'modulate', 'monochrome', 'negate', 'normalize', 'sepia-tone', 'threshold', 'unsharp');
foreach ($GDfeatures as $missingcolor => $features) {
	foreach ($features as $dummy => $feature) {
		echo ' <span style="background-color: '.($phpThumb->ImageMagickSwitchAvailable($feature) ? 'lime' : $missingcolor).';">'.htmlentities($feature).' | </span>';
	}
}
echo '</th><td>All 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.</td></tr>';


echo '<tr><th>GD features:</th><th colspan="2">';
$GDfeatures['red']    = array('JPG Support', 'PNG Support');
$GDfeatures['orange'] = array('GIF Read Support', 'GIF Create Support', 'FreeType Support');
foreach ($GDfeatures as $missingcolor => $features) {
	foreach ($features as $dummy => $feature) {
		echo '<div style="background-color: '.($gd_info[$feature] ? 'lime' : $missingcolor).';">'.htmlentities($feature).'</div>';
	}
}
echo '</th><td>PNG support is required for watermarks, overlays, calls to ImageMagick and other internal operations.<br>JPG support is obviously quite useful, but ImageMagick can substitute<br>GIF read support can be bypassed with ImageMagick and/or internal GIF routines.<br>GIF create support can be bypassed with ImageMagick (if no filters are applied)<br>FreeType support is needed for TTF overlays.</td></tr>';


echo '<tr><th>GD extension "EXIF"</th><th colspan="2" bgcolor="';
if (extension_loaded('exif')) {
	echo 'lime';
} elseif (@$ServerInfo['gd_string']) {
	echo 'orange';
}
echo '">'.(extension_loaded('exif') ? 'TRUE' : 'FALSE');
echo '</th><td>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.</td></tr>';


echo '<tr><th>php_sapi_name()</th><th colspan="2" bgcolor="';
$php_sapi_name = strtolower(function_exists('php_sapi_name') ? php_sapi_name() : '');
if (!$php_sapi_name) {
	echo 'red';
} elseif ($php_sapi_name == 'cgi-fcgi') {
	echo 'orange';
} elseif ($php_sapi_name == 'cgi') {
	echo 'yellow';
} elseif ($php_sapi_name == 'apache') {
	echo 'lime';
} else {
	echo 'green';
}
echo '">'.$php_sapi_name.'</th>';
echo '<td>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, <i>apache_lookup_uri()</i> will not work.</td></tr>';


echo '<tr><th>Server Software</th><th colspan="2" bgcolor="';
$server_software = getenv('SERVER_SOFTWARE');
if (!$server_software) {
	echo 'red';
} elseif (eregi('^Apache/([0-9\.]+)', $server_software, $matches)) {
	if (phpthumb_functions::version_compare_replacement($matches[1], '2.0.0', '>=')) {
		echo 'lightgreen';
	} else {
		echo 'lime';
	}
} else {
	echo 'darkgreen';
}
echo '">'.$server_software.'</th>';
echo '<td>Apache v1.x has the fewest compatability problems. IIS has numerous annoyances. Apache v2.x is often broken for <i>/~user/filename.jpg</i> style relative filenames using <i>apache_lookup_uri()</i>.</td></tr>';

echo '<tr bgcolor="#EEEEEE"><th colspan="4">&nbsp;</th></tr>';
echo '<tr bgcolor="#EEEEEE"><th>function_exists:</th><th colspan="2">Value</th><th>Comments</th></tr>';

$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+ && GD v2.0.1+'),
	'ImageFilter'           => array('yellow',     'PHP5 only. Required for some filters (but most can use ImageMagick instead)'),
);
foreach ($FunctionsExist as $function => $details) {
	list($color, $description) = $details;
	echo '<tr><th>'.$function.'</th><th colspan="2" bgcolor="';
	if (function_exists(strtolower($function))) {
		echo 'lime">TRUE';
	} else {
		echo $color.'">FALSE';
	}
	echo '</th><td>'.$description.'</td></tr>';
}


echo '<tr bgcolor="#EEEEEE"><th colspan="4">&nbsp;</th></tr>';
echo '<tr bgcolor="#EEEEEE"><th>Setting</th><th>Master Value</th><th>Local Value</th><th>Comments</th></tr>';


$SettingFeatures = array(
	'magic_quotes_runtime' => array('red',    'lime',   'This setting is evil. Turn it off.'),
	'magic_quotes_gpc'     => array('orange', '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 on (limiting max image resolution, no animated GIF resize). Temp files may be disabled. Features will be limited.'),
	'magic_quotes_runtime' => array('red', 'lime', 'This setting is evil. Turn it off.'),
);

foreach ($SettingFeatures as $feature => $FeaturesDetails) {
	list($color_true, $color_false, $reason) = $FeaturesDetails;
	echo '<tr><th>'.$feature.':</th>';
	echo '<th bgcolor="'.(@get_cfg_var($feature) ? $color_true : $color_false).'">'.$phpThumb->phpThumbDebugVarDump((bool) @get_cfg_var($feature)).'</th>';
	echo '<th bgcolor="'.(@ini_get($feature)     ? $color_true : $color_false).'">'.$phpThumb->phpThumbDebugVarDump((bool) @ini_get($feature)).'</th>';
	echo '<td>'.$reason.'</td></tr>';
}

$MissingFunctionSeverity = array(
	'shell_exec' => 'red',
	'system'     => 'red',
	'passthru'   => 'red',
	'exec'       => 'red',
);
$DisabledFunctions[0] = explode(',', @get_cfg_var('disable_functions'));
$DisabledFunctions[1] = explode(',',     @ini_get('disable_functions'));
echo '<tr><th>disable_functions:</th>';
for ($i = 0; $i <= 1; $i++) {
	echo '<th bgcolor="'.(count($DisabledFunctions[$i]) ? 'yellow' : 'lime').'">';
	$disabled_functions = '';
	foreach ($DisabledFunctions[$i] as $key => $value) {
		if (@$MissingFunctionSeverity[$value]) {
			$DisabledFunctions[$i][$key] = '<span style="background-color: '.$MissingFunctionSeverity[$value].';">'.$value.'</span>';
		}
	}
	echo implode(', ', $DisabledFunctions[$i]).'</th>';
}
echo '<td>Best if nothing disabled. Calls to ImageMagick will be prevented if exec+system+shell_exec+passthru are disabled.</td></tr>';


echo '<tr><th>memory_limit:</th><th bgcolor="';
$memory_limit = @get_cfg_var('memory_limit');
if (!$memory_limit) {
	echo 'lime';
} elseif ($memory_limit >= 32) {
	echo 'lime';
} elseif ($memory_limit >= 24) {
	echo 'lightgreen';
} elseif ($memory_limit >= 16) {
	echo 'green';
} elseif ($memory_limit >= 12) {
	echo 'darkgreen';
} elseif ($memory_limit >= 8) {
	echo 'olive';
} elseif ($memory_limit >= 4) {
	echo 'yellow';
} elseif ($memory_limit >= 2) {
	echo 'orange';
} else {
	echo 'red';
}
echo '">'.($memory_limit ? $memory_limit : '<i>unlimited</i>').'</th><th bgcolor="';
$memory_limit = @ini_get('memory_limit');
if (!$memory_limit) {
	echo 'lime';
} elseif ($memory_limit >= 32) {
	echo 'lime';
} elseif ($memory_limit >= 24) {
	echo 'lightgreen';
} elseif ($memory_limit >= 16) {
	echo 'green';
} elseif ($memory_limit >= 12) {
	echo 'darkgreen';
} elseif ($memory_limit >= 8) {
	echo 'olive';
} elseif ($memory_limit >= 4) {
	echo 'yellow';
} elseif ($memory_limit >= 2) {
	echo 'orange';
} else {
	echo 'red';
}
echo '">'.($memory_limit ? $memory_limit : '<i>unlimited</i>').'</th>';
echo '<td>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 / 5, 1).' megapixels' : '').'</td></tr>';


?>
</table>
</body>
</html>
Return current item: Open Media Collectors Database