Re: imagefilledpolygon() with a pattern
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: imagefilledpolygon() with a pattern

From: albert <groups@fastworx.com>
Date: Thu Jul 21 2005 - 13:37:29 CEST

By pure chance I stumbled across the imagesettile() method. This can be
used to fill a polygon (or any other shape) with a specific pattern.

So I wrote the following function to create a crosshash fill:

[code]
function imageCrossHashFill($image, $polygonPoints, $colour) {
  $r = hexdec(substr($colour, 0, 2));
  $g = hexdec(substr($colour, 2, 2));
  $b = hexdec(substr($colour, 4, 2));

  $crossHash = imagecreate(20, 20);
  $bg2 = imagecolorallocate($crossHash, 255, 255, 255);
  $red2 = imagecolorallocate($crossHash, $r, $g, $b);
  imageline($crossHash, 0, 0, 20, 20, $red2);
  imageline($crossHash, 0, 10, 10, 20, $red2);
  imageline($crossHash, 10, 0, 20, 10, $red2);
  imageline($crossHash, 20, 0, 0, 20, $red2);
  imageline($crossHash, 10, 0, 0, 10, $red2);
  imageline($crossHash, 20, 10, 10, 20, $red2);
  imagecolortransparent($crossHash, $bg2);

  imagesettile($image, $crossHash);
  imagefilledpolygon($image, $polygonPoints, count($polygonPoints) / 2,
IMG_COLOR_TILED);

  imagedestroy($crossHash);
}
[/code]

You can fill the polygon with anything by changing the $crossHash
image.

Have a good day
Received on Mon Oct 17 21:13:45 2005