phpimage-processingalpha-transparencygd2premultiplied-alpha

imagecopyresampled in php - premultiplied alpha issue


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:

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?


Solution

  • 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.