imagelinethick function

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@147348 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2003-12-26 21:10:09 +00:00
parent 61922cb80f
commit 14b1e4913e

View file

@ -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>.