GIF 画像 (PHP) に矢印を描画するために使用imagefilledpolygon
していますが、矢印の輪郭を黒くしたいと思います。最初に矢印の三角形を作成し、次に矢印効果のために三角形の底に太い線を描きます。
私が考える1つの解決策は、2つの三角形の矢印を作成することです。最初の矢印は黒で、最初の矢印よりもわずかに大きくなります(アウトライン効果を作成するため)が、その計算方法がわかりません。
どんな助けでも素晴らしいでしょう!
矢印 (頭と尾) を作成するコード:
function arrow($img, $x1, $y1, $x2, $y2, $alength, $awidth, $color) {
$distance = sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2));
$dx = $x2 + ($x1 - $x2) * $alength / $distance;
$dy = $y2 + ($y1 - $y2) * $alength / $distance;
$k = $awidth / $alength;
$x2o = $x2 - $dx;
$y2o = $dy - $y2;
$x3 = $y2o * $k + $dx;
$y3 = $x2o * $k + $dy;
$x4 = $dx - $y2o * $k;
$y4 = $dy - $x2o * $k;
imagelinethick($img, $x1, $y1, $dx, $dy, $color,3);
return imagefilledpolygon($img, array($x2, $y2, $x3, $y3, $x4, $y4), 3, $color);
}
この関数は、矢印の行に対して呼び出されます (参考までに)。
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);
}