PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

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

 March 03, 2022     composer-php, imagick, php     No comments   

Issue

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.


Solution

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.



Answered By - nice_dev
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,258,855

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing