0

I have a PNG image, which is partly transparent. What I need is to make one more color on the image transparent too. I searched on the internet and here as well and I found some tutorials, but the problem is, that when I try it, it does indeed make my desired color transparent, but it does not "add it" to the original transparent alpha channel, but instead creates a new alpha, so I end up with an image, where my desired color is transparent, but the original parts that were transparent too are now a solid black background.

So far I came up with the following code, which does what I described above:

<?php
header('Content-Type: image/png');
$file="image.png";

$im = imagecreatefrompng($file);

$new = imagecolorclosest($im, 255, 0, 255);
imagecolortransparent($im, $new);

imagepng($im);
imagedestroy($im);
?>

Any ideas how to do what I need? Thanks in advance.

StormeHawke
  • 5,987
  • 5
  • 45
  • 73
  • take a look at [this](http://stackoverflow.com/questions/2611852/imagecreatefrompng-makes-a-black-background-instead-of-transparent) question. – Srikanth Muttavarapu Oct 07 '14 at 13:28
  • I tried copying that into my code but it didnt do anything, could you perhaps help me with where exactly I should add the "$background = imagecolorallocate($simage, 0, 0, 0); // removing the black from the placeholder....." – user3790770 Oct 07 '14 at 13:34
  • I tried everything in the above mentioned links and still... the background is black. All I need is to add the specified color to the transparency, but it just seems impossible. – user3790770 Oct 07 '14 at 14:47

0 Answers0