Skip to content

Bug: ImageMagickHandler throws exception without imagick extension #6297

Closed
@blurpy

Description

@blurpy

PHP Version

7.4

CodeIgniter4 Version

4.2.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli-server (PHP built-in webserver)

Database

MariaDB v5.5

What happened?

I'm migrating an app from CodeIgniter 3 to 4, and when trying to use the new image library it throws an exception:

CodeIgniter\Images\Exceptions\ImageException

The framework needs the following extension(s) installed and loaded: IMAGICK.

I have never installed the imagick extension with ci3, and according to the documentation it should not be required in ci4 either:

The ImageMagick handler does NOT require the imagick extension to be loaded on the server. As long as your script can access the library and can run exec() on the server, it should work.

Steps to Reproduce

Having just the command line imagemagick tools installed without the imagick extension.

.env:

images.defaultHandler = 'imagick'
images.libraryPath = '/usr/bin/convert'
class Images extends BaseController {

    private BaseHandler $image;

    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);

        $this->image = Services::image(); // Exception thrown here
    }
...

Expected Output

Would expect the library to load without the imagick extension installed.

Anything else?

Looking at the description in the code, it seems to agree with the documentation in that the extension is not required:

* To make this library as compatible as possible with the broadest
* number of installations, we do not use the Imagick extension,
* but simply use the command line version.

However, the actual code looks for the extension and if it's not there it throws an exception in the constructor:

public function __construct($config = null)
{
parent::__construct($config);
// We should never see this, so can't test it
// @codeCoverageIgnoreStart
if (! (extension_loaded('imagick') || class_exists(Imagick::class))) {
throw ImageException::forMissingExtension('IMAGICK');
}

If I comment out throw ImageException::forMissingExtension('IMAGICK'); then the library allows me to resize an image, so the documentation seems to be correct in that the extension is not required.

I have not finished migration yet, so there could be some cases that do not work though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions