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
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
.
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
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');
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.
Try this: