imagick icon indicating copy to clipboard operation
imagick copied to clipboard

borderImage with transparent color not working properly in imagick7

Open myrecs opened this issue 3 years ago • 10 comments

borderImage function with any 'transparent' color string makes black corrupted image. any other colors work good

myrecs avatar Aug 15 '21 11:08 myrecs

I'm not seeing that. Can you say which version of ImageMagick you're using, and the exact color string you are seeing the problem with, and upload the 'corrupted' image.

Danack avatar Aug 15 '21 19:08 Danack

'versionNumber' => 1799, 'versionString' => 'ImageMagick 7.0.7-11 Q16 x64 2017-11-23 good_green_border test_img bad_transparent_border Here is image, good green border and bad transparent border

myrecs avatar Aug 15 '21 19:08 myrecs

For the exact 'color string', please can you give me the precise values you are using for $color, width and height on the line:

$imagick->borderImage($color, $width, $height);

as there are several ways for a color to be considered transparent.

Danack avatar Aug 15 '21 20:08 Danack

$imagick->borderImage('none', 50, 50); $imagick->borderImage('transparent', 50, 50); $imagick->borderImage('rgba(255,255,255,0)', 50, 50);

myrecs avatar Aug 15 '21 20:08 myrecs

noticed that when you do $imagick->borderImage('rgba(255,255,255,0)', 50, 50); alpha channel affects image itself not the border. i think it is the root of the problem.

myrecs avatar Aug 15 '21 20:08 myrecs

Yup, that looks like a bug.

For the borderImage operation, there is a composite operator parameter, which is hard-coded to Atop in the source for ImageMagick 7. It appears that this is a poor choice from https://imagemagick.org/script/command-line-options.php#border :

The -border operation is affected by the current -compose setting and assumes that this is using the default 'Over' composition method. It generates an image of the appropriate size colors by the current -bordercolor before overlaying the original image in the center of this net image. This means that with the default compose method of 'Over' any transparent parts may be replaced by the current -bordercolor setting.

It should default to 'Over' and it should be settable through the api.

Danack avatar Aug 16 '21 14:08 Danack

This probably affects frameImage also...

Danack avatar Oct 01 '21 11:10 Danack

oh, please can you test this also for the snapshot version of Imagick @myrecs ?

And there is a new function that allows setting the composite method use:

Imagick::borderImageWithComposite(
        ImagickPixel|string $border_color,
        int $width,
        int $height,
        int $composite // COMPOSITE_
): bool  {}

Danack avatar Nov 06 '21 13:11 Danack

@Danack with version you have posted (7.1.0-13 Q16 ) - borderImage also not works as it should be, same behaviour as in 7.0.7, nothing changed And borderImageWithComposite - Call to undefined method Imagick::borderImageWithComposite() - it is absent)

myrecs avatar Nov 06 '21 15:11 myrecs

Sorry, I screwed up due to tiredness.

I should have tagged the release of Imagick before asking you to test this.

Danack avatar Nov 06 '21 16:11 Danack