Verify ImageMagick Installation

My web host said ImageMagic was pre-installed on the server. I quickly looked through "ImageMagick" in the output of phpinfo (), and found nothing. I can not SSH on the server, so is there a way in PHP, can I verify the installation?

+65
php imagemagick
Nov 17 '10 at 19:22
source share
7 answers

Try the following:

<?php //This function prints a text array as an html list. function alist ($array) { $alist = "<ul>"; for ($i = 0; $i < sizeof($array); $i++) { $alist .= "<li>$array[$i]"; } $alist .= "</ul>"; return $alist; } //Try to get ImageMagick "convert" program version number. exec("convert -version", $out, $rcode); //Print the return code: 0 if OK, nonzero if error. echo "Version return code is $rcode <br>"; //Print the output of "convert -version" echo alist($out); ?> 
+41
Nov 17 '10 at 19:25
source share
 if (!extension_loaded('imagick')) echo 'imagick not installed'; 
+109
Nov 17 '10 at 19:34
source share

EDIT: The information and script below apply only to the iMagick class, which by default is not added with ImageMagick !!!

If I want to know if imagemagick is installed and actually works as a php extension, I paste this snippet into a web accessible file

 <?php error_reporting(E_ALL); ini_set( 'display_errors','1'); /* Create a new imagick object */ $im = new Imagick(); /* Create new image. This will be used as fill pattern */ $im->newPseudoImage(50, 50, "gradient:red-black"); /* Create imagickdraw object */ $draw = new ImagickDraw(); /* Start a new pattern called "gradient" */ $draw->pushPattern('gradient', 0, 0, 50, 50); /* Composite the gradient on the pattern */ $draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im); /* Close the pattern */ $draw->popPattern(); /* Use the pattern called "gradient" as the fill */ $draw->setFillPatternURL('#gradient'); /* Set font size to 52 */ $draw->setFontSize(52); /* Annotate some text */ $draw->annotation(20, 50, "Hello World!"); /* Create a new canvas object and a white image */ $canvas = new Imagick(); $canvas->newImage(350, 70, "white"); /* Draw the ImagickDraw on to the canvas */ $canvas->drawImage($draw); /* 1px black border around the image */ $canvas->borderImage('black', 1, 1); /* Set the format to PNG */ $canvas->setImageFormat('png'); /* Output the image */ header("Content-Type: image/png"); echo $canvas; ?> 

You should see a welcome graphic:

enter image description here

+28
Mar 16 '14 at 15:35
source share

You can easily check the Imagick class in PHP.

 if( class_exists("Imagick") ) { //Imagick is installed } 
+15
Nov 17 '10 at 19:27
source share

Try this one-time solution that should figure out where ImageMagick is, if you have access to it ...

It found all versions on the go of Godaddy.

Upload this file to your server and name it ImageMagick.php or something, then run it. You will receive all the necessary information ... I hope ...

Good luck.

 <? /* // This file will run a test on your server to determine the location and versions of ImageMagick. //It will look in the most commonly found locations. The last two are where most popular hosts (including "Godaddy") install ImageMagick. // // Upload this script to your server and run it for a breakdown of where ImageMagick is. // */ echo '<h2>Test for versions and locations of ImageMagick</h2>'; echo '<b>Path: </b> convert<br>'; function alist ($array) { //This function prints a text array as an html list. $alist = "<ul>"; for ($i = 0; $i < sizeof($array); $i++) { $alist .= "<li>$array[$i]"; } $alist .= "</ul>"; return $alist; } exec("convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. echo alist($out); //Print the output of "convert -version" echo '<br>'; echo '<b>This should test for ImageMagick version 5.x</b><br>'; echo '<b>Path: </b> /usr/bin/convert<br>'; exec("/usr/bin/convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. echo alist($out); //Print the output of "convert -version" echo '<br>'; echo '<b>This should test for ImageMagick version 6.x</b><br>'; echo '<b>Path: </b> /usr/local/bin/convert<br>'; exec("/usr/local/bin/convert -version", $out, $rcode); //Try to get ImageMagick "convert" program version number. echo "Version return code is $rcode <br>"; //Print the return code: 0 if OK, nonzero if error. echo alist($out); //Print the output of "convert -version"; ?> 
+7
Jul 18 2018-12-18T00:
source share

In bash:

 $ convert -version 

or

 $ /usr/local/bin/convert -version 

No need to write any PHP file just for verification.

+4
Jun 20 '17 at 14:02
source share

If your ISP / hosting service has installed ImageMagick and placed its location in the PATH environment variable, you can find which versions are installed and where they are used:

 <?php echo "<pre>"; system("type -a convert"); echo "</pre>"; ?> 
0
Jun 20 '17 at 17:25
source share



All Articles