vrana           Fri Dec 26 16:10:10 2003 EDT

  Modified files:              
    /phpdoc/en/reference/image/functions        imageline.xml 
  Log:
  imagelinethick function
  
Index: phpdoc/en/reference/image/functions/imageline.xml
diff -u phpdoc/en/reference/image/functions/imageline.xml:1.4 
phpdoc/en/reference/image/functions/imageline.xml:1.5
--- phpdoc/en/reference/image/functions/imageline.xml:1.4       Wed Feb 12 12:49:07 
2003
+++ phpdoc/en/reference/image/functions/imageline.xml   Fri Dec 26 16:10:09 2003
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
 <!-- splitted from ./en/functions/image.xml, last change in rev 1.2 -->
   <refentry id="function.imageline">
    <refnamediv>
@@ -21,8 +21,42 @@
      <function>imageline</function> draws a line from
      <parameter>x1</parameter>, <parameter>y1</parameter> to
      <parameter>x2</parameter>, <parameter>y2</parameter> (top left is
-     0, 0) in image im of color <parameter>color</parameter>.
+     0, 0) in image <parameter>image</parameter> of color 
<parameter>color</parameter>.
     </para>
+    <example>
+     <title>Drawing a thick line</title>
+     <programlisting role="php">
+<![CDATA[
+<?php
+
+function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1) {
+    /* this way it works well only for orthogonal lines
+    imagesetthickness($image, $thick);
+    return imageline($image, $x1, $y1, $x2, $y2, $color);
+    */
+    if ($thick == 1) {
+        return imageline($image, $x1, $y1, $x2, $y2, $color);
+    }
+    $t = $thick / 2 - 0.5;
+    if ($x1 == $x2 || $y1 == $y2) {
+        return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, 
$y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
+    }
+    $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
+    $a = $t / sqrt(1 + pow($k, 2));
+    $points = array(
+        round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),
+        round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),
+        round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),
+        round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),
+    );    
+    imagefilledpolygon($image, $points, 4, $color);
+    return imagepolygon($image, $points, 4, $color);
+}
+
+?>
+]]>
+     </programlisting>
+    </example>
     <para>
      See also <function>imagecreate</function> and
      <function>imagecolorallocate</function>.

Reply via email to