Viewed   54 times

My web hosting said ImageMagic has been pre-installed on the server. I did a quick search for "ImageMagick" in the output of phpinfo() and I found nothing. I can't SSH in the server so is there a way in PHP I can verify the installation?

 Answers

1

Try this:

<?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); 
?>
Wednesday, August 3, 2022
4

Your ImageMagick installation is not enough. You also need the Imagick package (possibly called php72-imagick or similar for home brew).

Imagick doesn't do the work itself, it is a native PHP extension for creating and modifying images using the ImageMagick API.

Try to search for the exact name of the package via brew search imagick.

Wednesday, November 16, 2022
 
4

You have to add extension=imagick.so in your php.ini file.

  • Location:

You can do some thing like this for the fastest way:

php -i | grep 'php.ini'

The result is like that:

Loaded Configuration File => /usr/local/lib/php.ini

Or call <?php phpinfo(); ?> from some php file to get this information :)

PS: Source

Monday, August 29, 2022
 
amahido
 
1

Imagick has a "setRegistry" method. http://php.net/manual/en/imagick.setregistry.php

You can use it to set the imagemagick temp path like so:

$i = new Imagick();
$i->setRegistry('temporary-path', '/efs');
Monday, October 17, 2022
 
5

I am hopeless at PHP but something like this seems to work for me:

#!/usr/local/bin/php -f
<?php

   $padding=10;
   $info = getimagesize("input.jpg");
   $width=$info[0];
   $height=$info[1];

   // Calculate dimensions of output image
   $canvasWidth=$width+4*$padding;
   $canvasHeight=$height+2*$padding;

   // create white canvas
   $output = imagecreatetruecolor($canvasWidth, $canvasHeight);
   $background = imagecolorallocate($output, 255, 255, 255);
   imagefill($output, 0, 0, $background);

   // read in original image
   $orig = imagecreatefromjpeg("input.jpg");

   // copy left third to output image
   imagecopy($output, $orig,$padding,             $padding,             0, 0, $width/3, $height);
   // copy central third to output image
   imagecopy($output, $orig,2*$padding+$width/3,  $padding,      $width/3, 0, $width/3, $height);
   // copy right third to output image
   imagecopy($output, $orig,3*$padding+2*$width/3,$padding,    2*$width/3, 0, $width/3, $height);

   // save output image
   imagejpeg($output,"result.jpg");
?>

If I start with this:

I get this as a result

I added the black outline afterwards so you can see the extent of the image.

Sunday, September 11, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :