문제

I have an issue with imagecopyresampled for buffers that use alpha values. apparently the algorithm premultiplies the pixels alpha values before filtering, this results in black borders arround objects.

Steps to reproduce:

  • take an image that is completely white in the RGB part and that has a (antialiased!!) white circle (go with a circle, not with a square!) on black background in the Alpha part (so the alpha part will have mostly totally white and totally black pixels, as well as some gradient pixels on the borders of the circle due to antialiasing - this means the input image is NOT premultiplied - it is straight/unmatted, because the RGB part of the image is completely white).

  • scaledown the image by half using imagecopyresampled

  • compose the result over a completely white image

What i'd expect: completely white image

What i get: a grayish border arround the outline of the circle

I'm pretty sure this is due to premultiplied alpha within the scaledown algorithm (the algorithm multiplies the pixels alpha value with it's rgb value to calculate the new rgb value - thus white pixels will become gray)

Does anyone know a workarround for this?

도움이 되었습니까?

해결책

I would suggest to try image magick for php.

http://www.php.net/manual/en/imagick.resizeimage.php

http://www.php.net/manual/en/imagick.scaleimage.php

in my experience all hassles concerning imaging in php just go away.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top