Timur Gafforov
Timur Gafforov

Reputation: 761

Imagick successfull installation but error occurs: Uncaught Error: Class 'imagick' not found

I've read a dozen of articles, but none provides a proper solution. I have an SSH access to my server and I installed the imagick through composer as follows:

composer require calcinai/php-imagick

The library successfully installed on both my local server (open server) and on the remote server. Then I do:

$imagick = new imagick();
$imagick->setResolution(300, 300); 

Everything works fine on my local machine, but on my web-hosting it returns Uncaught Error: Class 'imagick' not found. Do I need to do the require for all the files or something? Because I tried to add the following in the beginning:

require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/calcinai/php-imagick/src/Imagick.php';

now it throws me this: Uncaught Exception: Imagick::setResolution not implemented

Please, advice.

Upvotes: 0

Views: 1202

Answers (1)

nice_dev
nice_dev

Reputation: 17825

require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/calcinai/php-imagick/src/Imagick.php';

Above line is not required. As mentioned in the comments, Composer is strict with casing of class names and tweaking with cases of class names is discouraged as composer has proper strict autoloading of them in its classmaps.

$imagick = new Imagick();

Above line is the correct way of initialization. As far as the exception is concerned, their own internal implementation throws it as something yet to be implemented. Below is their method body they have,

Method definition:

/**
 * @param float $x_resolution
 * @param float $y_resolution
 * @return bool
 */
public function setResolution($x_resolution, $y_resolution)
{
    throw new Exception(sprintf('%s::%s not implemented', __CLASS__, __FUNCTION__));
}

As far as remote server is concerned, everything is performing fairly well there too. If you really need some implementation for setResolution, some other library might help.

Upvotes: 2

Related Questions