title: Convert to alpha using PHP GD
body: <p>I'm trying to achieve something close to what Fireworks does by using the convert to alpha filter (see <a href="http://erskinedesign.com/blog/fireworks-tips-convert-alpha/" rel="nofollow">http://erskinedesign.com/blog/fireworks-tips-convert-alpha/</a>). Is this possible using only the php gd functions?</p>
  
  <p>My code looks like:</p>
  
  <pre><code>$img = imagecreatefromstring(file_get_contents('...'));
  
  imagealphablending($img, true);
  $transparentcolour = imagecolorallocate($img, 255,255,255);
  imagecolortransparent($img, $transparentcolour);
  imagefilter($img, IMG_FILTER_GRAYSCALE);
  
  $w = imagesx($img);
  $h = imagesy($img);
  
  for ($x=0; $x&lt;$w; $x++)
  {
      for ($y=0; $y&lt;$h; $y++)
      {
          $color = imagecolorsforindex($img, imagecolorat($img, $x, $y));
  
          if ($color['alpha'] == 0)
              continue;
      }
  }
  imagepng($img);
  exit;
  </code></pre>
  
  <p>My idea is to convert to grayscale, measure how 'dark' a pixel is, then convert it to a black alpha, but I seem to be confusing myself.</p>