Asked  7 Months ago    Answers:  5   Viewed   26 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

15

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, March 31, 2021
 
Hexaholic
answered 7 Months ago
77

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, March 31, 2021
 
Dev
answered 7 Months ago
Dev
86

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

Wednesday, March 31, 2021
 
laurent
answered 7 Months ago
43

How do I set the "method" (from 0 to 6)?

Try this...

$im = new Imagick();
$im->pingImage($src);
$im->readImage($src);
$im->resizeImage($width,$height,Imagick::FILTER_CATROM , 1,TRUE ); 
$im->setImageFormat( "webp" );
$im->setOption('webp:method', '6'); 
$im->writeImage($dest); 

How do I set compression quality? (I tried setImageCompressionQuality and it does not work, ie the output is always the same size)

Imagick::setImageCompressionQuality seems to work for me, but note that webp:lossless becomes enabled if the values is 100, or greater (see source). You can test toggling lossless to see how that impacts results.

$img->setImageFormat('webp');
$img->setImageCompressionQuality(50);
$img->setOption('webp:lossless', 'true');

Edit from comments

Try testing the image conversion to webp directly with the cwebp utility.

cwebp -q 50 photo.jpg -o photo.webp

This will also write some statistical information to stdout, which can help debug what's happening.

Saving file 'photo.webp'
File:      photo.jpg
Dimension: 1170 x 1170
Output:    4562 bytes Y-U-V-All-PSNR 55.70 99.00 99.00   57.47 dB
block count:  intra4: 91
              intra16: 5385  (-> 98.34%)
              skipped block: 5357 (97.83%)
bytes used:  header:             86  (1.9%)
             mode-partition:   2628  (57.6%)
 Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |       0%|       0%|       0%|      98%|    5476
      quantizer:  |      45 |      45 |      43 |      33 |
   filter level:  |      14 |      63 |       8 |       5 |

Also remember that for some subject matters, adjusting the compression quality doesn't always guaranty a file size decrease. But those are extreme edge cases.

Wednesday, March 31, 2021
 
AntoineB
answered 7 Months ago
24

Edit this file:

/Applications/MAMP/Library/bin/envvars

Comment out the following lines:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"

export DYLD_LIBRARY_PATH

Saturday, May 29, 2021
 
GGio
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :