简体   繁体   中英

PHP Imagick class working when called from Web Server but not from Command Line

I'm running into a very frustrating problem when using Imagick in PHP.

Simple code:

$image = '1551660111_7801.jpg';
$imageBG = new Imagick();
$imageBG->readImage($image);
$imageBG->resizeImage('1280', '720', 1, 1, true);
$imageBG->writeImage ('test.jpg');

When I run this via Chrome, no issues, generates the new file.

But when I run through terminal like this

php test.php

I get this error

Fatal error: Class 'Imagick' not found in ../test.php on line 8

Check your PHP version on CLI and on web server.

on cli:

php -v

on web server open phpinfo(); command in some *.php file. It is possible that you have installed ImageMagick as PHP 5.6 extension and it is used by web server, but you CLI php version is PHP7

The path to the included file has to fit for both calls. Make sure you call the test.php from the same path as a web browser would.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM