Skip to content

Commit

Permalink
fix defaults for shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergix44 committed Sep 24, 2023
1 parent e1af58b commit 23dbc5e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Shapes/Shape.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

abstract class Shape
{
protected ?Color $background = null;
protected Color $background;

protected Color $borderColor;

protected int $borderWidth = 0;
protected int $borderWidth = 1;

public function __construct()
{
$this->background = Color::transparent();
$this->borderColor = Color::black();
}

public function hasBorder(): bool
{
Expand All @@ -20,7 +26,7 @@ public function hasBorder(): bool
public function border(int $width, Color $color = null): self
{
$this->borderWidth = $width;
$this->borderColor = $color ?? Color::transparent();
$this->borderColor = $color ?? Color::black();

return $this;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ function prepare($instance, string $name, Backend $driver, string $ext = 'png'):
100,
], function ($draw) {
$draw->background(Color::fuchsia());
$draw->border(0);
})
->save($out, quality: 100);

Expand All @@ -485,12 +486,33 @@ function prepare($instance, string $name, Backend $driver, string $ext = 'png'):
unlink($out);
})->with('drivers', 'baboon');

it('can draw a polygon on an image with no arguments', function ($driver, $file) {
[$out, $expected] = prepare($this, 'baboon_polygon_no_arguments', $driver);

Image::make($file, $driver)
->polygon([
10,
10,
100,
100,
10,
100,
])
->save($out, quality: 100);

expect($out)
->toBeFile()
->imageSimilarTo($expected);
unlink($out);
})->with('drivers', 'baboon');

it('can draw a rectangle on an image', function ($driver, $file) {
[$out, $expected] = prepare($this, 'baboon_rectangle', $driver);

Image::make($file, $driver)
->rectangle(10, 30, 100, 100, function ($draw) {
$draw->background(Color::fuchsia());
$draw->border(0);
})
->save($out, quality: 100);

Expand Down
Binary file added tests/Images/Gd/baboon_polygon_no_arguments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 23dbc5e

Please sign in to comment.