A PHP test script

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ridera

A PHP test script

Post by ridera »

Thought folks may find this PHP script helpful for testing their IM installations. It lists the versions for the 4 main command tools, the IM fonts and colors available, the IM configuration, draws a nifty shadowed label, and has a debug mode to show command error details.

The script is well documented and easily configured to fit your installation. It uses the PHP exec() function. You may need to modify the paths to your tools, [e.g., INDENTIFY]

Simply make a file with the script and execute it.

Code: Select all

<?php
/**
 *
 * Designed by Alan Rider
 *
 *
 */

	$convert= "/usr/local/bin/convert";						//paths to Imagemagick components

	$identify= "/usr/local/bin/identify";					// Best not to use simply /convert

	$montage= '/usr/local/bin/montage';

	$mogrify= '/usr/local/bin/mogrify';

	$debug= (isset($_GET['debug']))? TRUE : FALSE;

	$report= "<p style=\"margin:1em auto 0 auto; color:blue; font-size:12pt\">Append 'config' argument to URL [i.e. URL?config] to include configuration stuff and/or 'debug' argument to see a debug report.  </p>\n\n";

	$cmd_debug= ($debug)? '-debug exception' : '';

	$font= 'Bookman-Demi';

	$font= 'Bookman-DemiItalic';

	$text= "Versions, Fonts and Colors";

	$text= "testing";

	$text= "Candidates for the Board of Directors";

	$php5= ((int)PHP_VERSION >= 5)? TRUE : FALSE;

	if($php5)date_default_timezone_set('America/New_York');							//Set as needed, php5.1+

	$text= 'Image created and saved: ' . date('j M Y h:i:s A');

	$file= '/IMtest.jpg';

	$fpfile= getcwd() . $file;

	$img= (isset($_GET['no_img']))? FALSE : TRUE;

	$dirname= basename(getcwd());

	if($img && !is_writeable(getcwd())) die ("<p style=\"margin:1em auto 0 auto; color:red\">Directory [$dirname] permissions prohibit writing files. Change to 757 and run once.  Then restore permissions to 755. </p>
<p style=\"margin:1em auto 0 auto; color:red\">You can supress the image file writing test with URL argument '?no_img'</p>\n\n");

	$command="-background lightblue -fill blue -font $font -pointsize 72 label:$text";

/*
-size 860x85 xc:transparent -font Bookman-DemiItalic -pointsize 72 -draw "text 25,60 'Magick'"
    -channel RGBA -gaussian 0x6 -fill darkred -stroke magenta -draw "text 20,55 'Magick'" fuzzy-magick.png
*/
	$command= "-size 900x85 xc:#ffffee -font $font -pointsize 30 -draw \"text 10,60 '$text'\" -channel RGBA -gaussian 0x6 -fill darkred -stroke magenta -draw \"text 5,55 '$text'\"";


//	$command= "-size 320x85 xc:transparent -font $font -pointsize 72 -draw 'text 25,60 $text' -channel RGBA -gaussian 0x6 -fill darkred -stroke magenta";

	$report .= "<br><p>Command => <br>\n" . $command . "</p>\n\n";

//here is the command line
	if($img) exec("$convert $cmd_debug $command $fpfile", $IMarray, $code);

	if($img) $report .= "<p style=\"margin:1em auto 0 auto; color:blue; font-size:12pt\">Depending on your brower's cache settings, the image may not update. Try ctrl-R.</p>";

	if(!$img) $report .= "<p style=\"margin:1em auto 0 auto; color:blue; font-size:12pt\">You appended 'no_img', so either no image will show or a old image will be rendered, if it exists.</p>";

	$report .= "<img style=\"margin:2em auto 2em auto\" alt=\"image missing\" src=\".$file\">\n\n"; //whatch the dot

	if($php5) $report .= "<p style=\"color:blue; font-size:12pt\">Time is EST or DEST for php5</p>";

	if(!$php5) $report .= "<p style=\"color:blue; font-size:12pt\">Time is server time for php4</p>";

	$report .= "<div style=\"clear:both, height:1em\"></div>\n";

	if(($debug OR $code != 0)){

		$report .= "<pre>" . print_r($IMarray, TRUE) ."</pre>\n";
		$report .= "<br>Error code: " . $code . '<br>\n';
	}//end if

 	exec("$identify -version", $version);

	$report .= 'IDENTIFY version: ' . $version[0] ."<br>\n";

	exec("$convert -version", $version);

	$report .= 'CONVERT version: ' . $version[0] ."<br>\n";

	exec("$montage -version", $version);

	$report .= 'MONTAGE version: ' . $version[0] ."<br>\n";

	exec("$mogrify -version", $version);

	$report .= 'MOGRIFY version: ' . $version[0] ."<br>\n";

	if(isset($_GET['config']))	{
		exec("$identify -debug configure -list type", $configarray);

		$report .= "Configuration: <pre>" . print_r($configarray, TRUE) ."</pre>";
	}

	exec("$identify -list type", $listarray);

	$report .= "<br><br>ImageMagic fonts: <pre>" . print_r($listarray, TRUE) ."</pre>";

	exec("$identify -list color", $colorarray);

	$report .= "<br><br>ImageMagic colors: <pre>" . print_r($colorarray, TRUE) ."</pre>";

	echo $report;
?>
Post Reply