1

I can successfully add a transparent rectangle to an area of a saved PNG file, but it has a faint border around it, which can be seen on the final image. I want to remove this.

The code I use to add the rectangle is:

$dest=imagecreatefrompng("originalFilename.png");
$red = imagecolorallocate($dest, 255, 0, 0);
imagecolortransparent($dest, $red);
imagefilledrectangle($dest, 0, 0, 50, 25, $red);
imagepng($dest, "newFilename.png");

and the result looks like this: Image showing rectangle outline

The transparency works fine, showing in this example a white background behind... but you can see that in the top left there's the faint outline of the transparent rectangle. This is what I want to remove.

I've since tried putting a box over the edge (it would be white to match the background of the image, but using green for display purposes here), but that box gets a slightly red huhe around it too!?!? Really strange. Like this red hue

Grateful for any clues. This is not the same as the suggested duplicate as it deals specifically with the hue that's left around the border of the transparent area and also any object made to go in that area.

haverer
  • 21
  • 3
  • Is the background always white? A dirty hack would be to draw a white line over the faint grey line. – Andreas May 05 '19 at 11:43
  • @andreas Alas, No! – haverer May 05 '19 at 11:44
  • 1
    Possible duplicate of [PHP/GD - transparent background](https://stackoverflow.com/questions/15246813/php-gd-transparent-background) – miken32 May 05 '19 at 16:48
  • Just read through it and not the same issue. I've got around my particular issue by not making a section of the image transparent, and instead layering my image and text... But that's specific to what I needed to do, it doesn't address the fact that any shape added to a an area made transparent gets this annoying hue. I'll leave the question open in case anyone can solve for future visitors. – haverer May 06 '19 at 03:48

0 Answers0