How do I check it's installed?
How do I check it's installed?
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.
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
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
Is the newer PECL imagick module installed
Is Command line available and working (the IM bin should be added to the servers command 'PATH', in its startup script)
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.
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";
?>
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" ;
?>
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'");
?>
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: How do I check it's installed?
Oof, just use
Code: Select all
<?php if (extension_loaded('magickwand')) { ... } ?>
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How do I check it's installed?
you can do that, but the test was not just for the module, but weather the module is actually working!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: How do I check it's installed?
This part of anthony's code doesn't work, at least for
This is result. Thus error report doesn't work.
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" ;
imagick_failedreason($handle) and imagick_faileddescription($handle) seem to be essentially useless since they require a good resource in order to 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:
Re: How do I check it's installed?
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.
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?
A failed install can result in it being reported true, but in all other cases where it is not installed, it will report false.ridera wrote:function_exists("NewMagickWand") reports TRUE