title: PHP/GD - transparent background
body: <p>I want to do the following in PHP in combination with GD. ImageMagick is not an option, unfortunately, but this seems like such a common problem that there <em>has</em> to be a solution, I just can't seem to find it.</p>
  
  <p>I want to create a PNG with a transparent background. Then I want to draw a rectangle on it, copy an image on it, and add some text. One way of doing this is as follows:</p>
  
  <pre><code>$image = ImageCreateTrueColor (800, 600);
  imagecolortransparent ($image, 0); //0 is pure black, the default fill color
  imagerectangle (...);
  //code to copy an image
  imagettftext ($image, ...);
  imagepng ($image);
  </code></pre>
  
  <p>This works fine, except that part of the copied image might be black, and/or the text might be black. This then also becomes transparent, which is something I <strong>don't</strong> want.</p>
  
  <pre><code>imagefill ($image, 0,0, 0x7FFF0000);
  imagetransparent ($image, 0x7FFF0000);
  </code></pre>
  
  <p>The above code is something I found online, which fills it with red, then makes red transparent. Again, this causes all red in the image to become transparent. I could choose a color that is unlikely to occur, but I can't guarantee this.</p>
  
  <p>Is there something I'm missing? Can this be fixed?
  Thanks for your replies!</p>