Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set image alpha channel #279

Open
bymayo opened this issue Oct 10, 2019 · 4 comments
Open

Unable to set image alpha channel #279

bymayo opened this issue Oct 10, 2019 · 4 comments

Comments

@bymayo
Copy link

bymayo commented Oct 10, 2019

We're getting the error ImagickException Unable to set image alpha channel when using effects grayscale, gamma and colorBlend using Imagick:

{% set heroImageTransform = craft.imager.transformImage(
    heroImage, 
    { 
            width: 700,
            height: 700,
            effects: { 
                grayscale: true, 
                gamma: 1.1, 
                colorBlend: ['#262672']
            }
    }
) %}

This seems to work fine locally but not on our staging env. The PHP versions are the same and so are the ImageMagick versions:

Version: ImageMagick 6.7.8-9 2019-08-08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

I've checked the It seems to be choking on this part of the plugin:

if (ImagerService::$imageDriver === 'imagick') {
    /** @var ImagickImage $imageInstance */
    $imagickInstance = $imageInstance->getImagick();

    $hasTransparency = $imagickInstance->getImageAlphaChannel();
    $imagickInstance->setImageType(\Imagick::IMGTYPE_GRAYSCALE);

    if ($hasTransparency) {
        $imagickInstance->setImageAlphaChannel(\Imagick::ALPHACHANNEL_ACTIVATE);
        $imagickInstance->setBackgroundColor(new \ImagickPixel('transparent'));
    }
}

Is this possibly related to the PR #142, which I'm unsure if it got merged or not, and also it seems old.

Using:

PHP 7.0.33
MySQL 5.7
Craft CMS 3.3.4.1
Imager 2.2.0

@aelvan
Copy link
Owner

aelvan commented Oct 12, 2019

What type of image is it (gif, png, jpg), and is it one image in particular or all images/...of that type?
What line is the stacktrace pointing to, is it $imagickInstance->setImageAlphaChannel(\Imagick::ALPHACHANNEL_ACTIVATE);?
Can you also check what the imagick version is (see "Image driver & version" under Utilities > System report)?

@bymayo
Copy link
Author

bymayo commented Oct 14, 2019

The file is a PNG with transparency, but i'm sure we did try it with a Jpeg but still get this the error.

The line is like you said:

$imagickInstance->setImageAlphaChannel(\Imagick::ALPHACHANNEL_ACTIVATE);

The Image Driver version is Imagick 3.4.4 (ImageMagick 6.7.8-9). We recently update the server to this version to match our local one (Which doesn't throw this error)

@aelvan
Copy link
Owner

aelvan commented Oct 15, 2019

I was able to reproduce this by compiling ImageMagick 6.7.8-10 and Imagick 3.4.4. But I've not been able to find a solution or workaround for the issue. Something is missing/wrong with that version of ImageMagick and/or Imagick, the code works in both older and newer versions I've tested.

My only advise would be to either upgrade ImageMagick, or work around the issue. The grayscale effect can be replaced by modulate: [100, 0, 100], but the same issue is in the colorBlend effect, and replacing that with something that gives the exact same result is a bit more difficult.

Please not that you can also make your own, custom effects if you need more complex logic to produce the desired effect.

@bymayo
Copy link
Author

bymayo commented Oct 15, 2019

@aelvan Okay yeah, I double checked locally and that version is Imagick 3.4.3 (ImageMagick 6.9.6-2) so I might downgrade to these versions if possible as I know these work. Will try this and update the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants