# Generating a semi-transparent image with PHP



## cowplopmorris (Jun 7, 2006)

Hi,
As the title suggests, I am trying to create a semi-transparent image with PHP, with GET variables sent to the script.

Below is what I have so far; I've linked to the image as well as providing the code.

I've got as far as making a semi-transparent rectangle, but it seems to put it on a black background. Also, as you can see, I've tried creating a black background then setting it as the imagecolortransparent, but this had no effect.

Is this possible with GD, or if not, with MagickWand?

Thanks in advance.

http://ezramorris.co.uk/test/trans/back.php?red=225&blue=0&green=225&opacity=50

```
<?php
  $size=100;
  // Create image object of 100x100px
  $image=imagecreatetruecolor($size, $size);

  // This is the colour which will be our transparent colour
  $back=imagecolorallocate($image, 0, 0, 0);
  imagefilledrectangle($image, 0, 0, $size, $size, $back);

  // Set black to be our transparent colour
  imagecolortransparent($image, $back);

  // Create color ID using our colours
  $color=imagecolorallocatealpha($image, $_GET['red'], $_GET['green'], $_GET['blue'], $_GET['opacity']);
  // Create a rectangle filled with our colour
  imagefilledrectangle($image, 0, 0, $size, $size, $color);

  // Set the correct header
  header('Content-type: image/png');

  // Output the image
  imagepng($image);
  imagedestroy($image);
?>
```


----------

