Skip to content

Commit ed8dcb6

Browse files
committed
minor fixes wrt antialiasing
Releases v0.1.1
1 parent cfac8d1 commit ed8dcb6

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "runalyze/static-maps",
33
"description": "Library to create static images from various map tile providers.",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"license": "MIT",
66
"require": {
77
"php": ">=7.0",

src/Drawer/AntialiasDrawer.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class AntialiasDrawer
1818
/** @var bool */
1919
protected $IsNativeFunctionAvailable;
2020

21+
/** @var bool */
22+
protected $UseNativeFunctionIfAvailable = false;
23+
2124
/** @var float */
2225
protected $AntialiasThreshold;
2326

@@ -27,9 +30,14 @@ public function __construct(float $antialiasThreshold = 0.0)
2730
$this->AntialiasThreshold = $antialiasThreshold;
2831
}
2932

33+
public function enableNativeAntialiasingIfAvailable(bool $flag)
34+
{
35+
$this->UseNativeFunctionIfAvailable = $flag;
36+
}
37+
3038
public function drawLine($resource, $x1, $y1, $x2, $y2, int $r, int $g, int $b, float $alpha = 100.0, int $lineWidth = 1)
3139
{
32-
if ($this->IsNativeFunctionAvailable) {
40+
if ($this->IsNativeFunctionAvailable && $this->UseNativeFunctionIfAvailable) {
3341
$this->drawNativeLine($resource, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha, $lineWidth);
3442
} else {
3543
$this->drawAntialiasLine($resource, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha, $lineWidth);
@@ -38,6 +46,11 @@ public function drawLine($resource, $x1, $y1, $x2, $y2, int $r, int $g, int $b,
3846

3947
protected function drawNativeLine($resource, $x1, $y1, $x2, $y2, int $r, int $g, int $b, float $alpha = 100.0, int $lineWidth = 1)
4048
{
49+
$x1 = (int)round($x1);
50+
$x2 = (int)round($x2);
51+
$y1 = (int)round($y1);
52+
$y2 = (int)round($y2);
53+
4154
imagesetthickness($resource, $lineWidth);
4255
imagealphablending($resource, true);
4356
imageantialias($resource, true);

src/Feature/Route.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Route implements FeatureInterface
3939
/** @var bool */
4040
protected $Antialiasing;
4141

42+
/** @var bool */
43+
protected $AntialiasingNative = false;
44+
4245
/** @var float [px] */
4346
protected $LineSimplificationTolerance = 0.0;
4447

@@ -59,9 +62,10 @@ public function __construct(array $coordinates, $lineColor = '#000', int $lineWi
5962
$this->AntialiasDrawer = new AntialiasDrawer();
6063
}
6164

62-
public function enableAntialiasing(bool $flag)
65+
public function enableAntialiasing(bool $flag = true, bool $nativeFlag = false)
6366
{
6467
$this->Antialiasing = $antialiasing;
68+
$this->AntialiasingNative = $nativeFlag;
6569
}
6670

6771
public function enableLineSimplification(float $pixelTolerance = 10)
@@ -83,6 +87,8 @@ protected function getLineColorArray($lineColor): array
8387

8488
public function render(ImageManager $imageManager, Image $image, ViewportInterface $viewport)
8589
{
90+
$this->AntialiasDrawer->enableNativeAntialiasingIfAvailable($this->AntialiasingNative);
91+
8692
foreach ($this->LineSegments as $segment) {
8793
$numPoints = count($segment);
8894
$lastPoint = 0;
@@ -106,7 +112,7 @@ public function render(ImageManager $imageManager, Image $image, ViewportInterfa
106112

107113
$this->truncateStartAndEndPointsBy(0.2, $x1, $y1, $x2, $y2);
108114

109-
if ($this->Antialiasing && !function_exists('imageantialias')) {
115+
if ($this->Antialiasing) {
110116
$this->AntialiasDrawer->drawLine(
111117
$image->getCore(),
112118
$x1,
@@ -120,6 +126,7 @@ public function render(ImageManager $imageManager, Image $image, ViewportInterfa
120126
$this->LineWidth
121127
);
122128
} else {
129+
imagesetthickness($image->getCore(), $this->LineWidth);
123130
$image->line($x1, $y1, $x2, $y2, $this->LineCallback);
124131
}
125132

0 commit comments

Comments
 (0)