Page 1 of 1

How do I check it's installed?

Posted: 2006-12-12T06:13:03-07:00
by BlueStream
How do I check if MagickWand for PHP is installed.

I tried function_exists("NewMagickWand") but that doesn't work.

I had an image resizing feature on my board before but when the MagickWand installation went south, without the proper checks, I ended up getting errors.

So. Is there any bit of code to check if MagickWand is installed?

Cheers,
Shawn.

Posted: 2006-12-12T09:36:46-07:00
by monsters
phpinfo will tell you. if installed there is a magickwand section.

eg:

magickwand
MagickWand Backend Library ImageMagick
MagickWand Extension Version 0.1.8

Posted: 2006-12-12T09:43:54-07:00
by BlueStream
no sorry.. I need it in a script... if installed, create instance and resize, else do nothing...

UPDATE:
if (function_exists("NewMagickWand")) is a valid solution... Apparently it wasn't installed properly and halfway through, the program failed. So it works now.

Posted: 2006-12-21T17:12:47-07:00
by anthony
These are some current tests I am using for testing the PHP installation (with all the bells and whistles) I am building.

Is MagickWand working, "image.jpg" should be in the same directory.
(this also has an example 'output image' test, but commented out

Code: Select all

<?
$resource = NewMagickWand();
MagickReadImage( $resource, 'image.jpg' );

// header( 'Content-Type: image/jpeg' );
// MagickEchoImageBlob( $resource );

$width = MagickGetImageWidth( $resource );
$height = MagickGetImageHeight( $resource );
echo "Image size, in pixels, is:  width $width x height $height";
?>
Is the newer PECL imagick module installed

Code: Select all

<?
        $handle = imagick_readimage( getcwd() . "/animated.gif" ) ;
        if ( imagick_iserror( $handle ) )
        {
                $reason      = imagick_failedreason( $handle ) ;
                $description = imagick_faileddescription( $handle ) ;

                print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;
                exit ;
        }
        print "Number of frames in image: " . imagick_getlistsize( $handle ) .
              "<BR>\n" ;
?>
Is Command line available and working (the IM bin should be added to the servers command 'PATH', in its startup script)

Code: Select all

<?
  header('Content-Type: text/plain');
  system("exec 2>&1; type convert");
  system("exec 2>&1; convert -version");
  system("exec 2>&1; convert -list type");
  system("exec 2>&1; identify -verbose 'image.jpg'");
?>
This last lists where convert was installed, its version, what fonts Im things it has, and a verbose indentification of your test JPG image.

If your ISP did there job well, at least two of the above should be working, if not all three!
If they suffed up the command path, and you knwo exactly where IM commands are you can hardcode the IM command location into the last script.

The 'exec' are to ensure IM errors also are reported. In a working program you probably should have a 'debug' and 'working' mode, so you can see errors if they exist.

Re: How do I check it's installed?

Posted: 2007-03-28T17:23:17-07:00
by Matthew Ratzloff
Oof, just use

Code: Select all

<?php if (extension_loaded('magickwand')) { ... } ?>

Re: How do I check it's installed?

Posted: 2007-03-28T18:48:26-07:00
by anthony
you can do that, but the test was not just for the module, but weather the module is actually working! :lol:

Re: How do I check it's installed?

Posted: 2007-08-06T07:19:48-07:00
by ridera
This part of anthony's code doesn't work, at least for

Code: Select all

	
$handle = imagick_readimage($org_image) ;  //image does not exist just for test
var_dump($handle);       //Not really binary, only false if error

       if (imagick_iserror( $handle ) )  //This doesn't work, see var_dump below
        {
                $reason      = imagick_failedreason($handle) ;
                $description = imagick_faileddescription($handle) ;

                print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>handle: $handle\n" ;
                exit ;
        }
        print "Number of frames in image: " . imagick_getlistsize( $handle ) .
              "<BR>\n" ;
This is result. Thus error report doesn't work.
bool(false)
Warning: imagick_iserror() expects parameter 1 to be resource, boolean given in /home/ridera/public_html/imagemagick/MagickWand.php on line 35

Warning: imagick_getlistsize() expects parameter 1 to be resource, boolean given in /home/ridera/public_html/imagemagick/MagickWand.php on line 43
Number of frames in image:
imagick_failedreason($handle) and imagick_faileddescription($handle) seem to be essentially useless since they require a good resource in order to work.

Re: How do I check it's installed?

Posted: 2007-08-06T08:38:47-07:00
by BlueStream
function_exists("NewMagickWand")

Re: How do I check it's installed?

Posted: 2007-08-06T09:21:44-07:00
by ridera
function_exists("NewMagickWand") reports TRUE

Re: How do I check it's installed?

Posted: 2007-08-07T11:33:57-07:00
by ridera
I'm familiar with using PHP exec() and IM command line stuff. Recently thought I'd learn about MagickWand for PHP. Had the sam problem as you.

Here is a test script that should help. Just make a php file with it.

Code: Select all

<?php

/**
 *
 * Designed by Alan Rider
 */


	function microtime_float(){
	  list($usec, $sec) = explode(" ", microtime());
	  return ((float)$usec + (float)$sec);
	}

	$report= "<html><body style= \"margin:5%\">\n\n";

	if(isset($_GET['info']))echo phpinfo();

	$report .= MagickGetVersionString() . "<br>\n\n";

	$report .= 'MagickWand release date: ' . MagickGetReleaseDate()  . "<br>\n\n";

	$report .= (extension_loaded('magickwand'))?  "MagickWand extension is loaded" : "MagickWand extension is not loaded";
	$report .=  "<br>\n\n";

	$report .= (function_exists("NewMagickWand"))?  "New MagickWand loaded successfully" : "New MagickWand failed to load";
	$report .=  "<br><br>\n\n";

	$resource = 		NewMagickWand();
	$dwand = 			NewDrawingWand();
	$pwand = 			NewPixelWand();
	$org_image=  		getcwd() . '/flower_original.jpg';  			//full path required
	$resized_org_img=	'./saved_flower_org.jpg';						//relative path for <img src=....>
	$new_width=			400;											//Height is computed to preserve aspect ratio
	$label_img=			'./test_label.gif';

	$time_start = microtime_float();

	if(!MagickReadImage($resource, $org_image)){
		$report .= "Error reading image at $org_image " . MagickGetExceptionString($resource) . "<br><br>\n\n";
	}

	$width = MagickGetImageWidth($resource);
	$height = MagickGetImageHeight($resource);

	$report .= "Orginal Image size, width: {$width}px x height: {$height}px <br>\n\n";

	$new_height= round($new_width/$width*$height);

	MagickResizeImage($resource, $new_width, $new_height, MW_QuadraticFilter, 1.0 );

	$width = MagickGetImageWidth($resource);
	$height = MagickGetImageHeight($resource);

	$report .= "Resized Image size, width: {$width}px x height: {$height}px <br><br>\n\n";

	MagickWriteImage($resource,  $resized_org_img);

	$time_end = microtime_float();

	$report .= "<p style=\"margin:1em auto 2em auto; color:blue; font-size:12pt\">Processing time to resize and write image file ==> " . round($time_end - $time_start, 2) . "</p>\n\n";

	$report .= "<img alt=\"image missing\" src=\"$resized_org_img\">\n\n";

	MagickNewImage($resource, $new_width, $new_height, 'blue');

	PixelSetColor($pwand, "red");
	DrawSetFont($dwand, "Times-BoldItalic");
	DrawSetFontSize($dwand, 40);
	DrawSetFillColor($dwand, $pwand);

	MagickAnnotateImage($resource, $dwand, 40, 120, 0, "MagickWand" );

	MagickSetImageFormat($resource, 'jpeg');

	MagickWriteImage($resource,  $label_img);

	$report .= "<img alt=\"image missing\" src=\"$label_img\">\n\n";

	$report .= "<p style=\"color:red\">Font type is wrong in label, path problem, should be Times-BoldItalic, I'm working on it.</p>\n\n";

	$report .= "<pre>". print_r(MagickQueryFonts('*'), TRUE) . "</pre>\n\n";

	DestroyMagickWand($resource);

	$report .= "</body></html>\n\n";

	echo $report;

?>

Re: How do I check it's installed?

Posted: 2007-08-11T07:44:03-07:00
by BlueStream
ridera wrote:function_exists("NewMagickWand") reports TRUE
A failed install can result in it being reported true, but in all other cases where it is not installed, it will report false.