Skip to content

Commit

Permalink
Change to using Picture objects
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Jan 16, 2024
1 parent ea05bb8 commit f84a5a0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
17 changes: 13 additions & 4 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SimonHamp\TheOg\Layout\Layouts\Standard;
use SimonHamp\TheOg\Theme as BuiltInTheme;
use SimonHamp\TheOg\Theme\BackgroundPlacement;
use SimonHamp\TheOg\Theme\Picture;

class Image
{
Expand All @@ -22,11 +23,11 @@ class Image

public readonly string $callToAction;
public readonly string $description;
public readonly string $picture;
public readonly Picture $picture;
public readonly string $title;

public readonly string $url;
public readonly string $watermark;
public readonly Picture $watermark;

public function __construct()
{
Expand Down Expand Up @@ -55,8 +56,12 @@ public function description(string $description): self
/**
* The picture to display
*/
public function picture(string $picture): self
public function picture(string|Picture $picture): self
{
if (is_string($picture)) {
$picture = new Picture($picture);
}

$this->picture = $picture;
return $this;
}
Expand All @@ -82,8 +87,12 @@ public function url(string $url): self
/**
* The watermark image
*/
public function watermark(string $watermark, ?float $opacity = 1.0): self
public function watermark(string|Picture $watermark): self
{
if (is_string($watermark)) {
$watermark = new Picture($watermark);
}

$this->watermark = $watermark;
return $this;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Interfaces/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SimonHamp\TheOg\Border;
use SimonHamp\TheOg\Image as Config;
use SimonHamp\TheOg\Layout\TextBox;
use SimonHamp\TheOg\Theme\Picture;

interface Layout
{
Expand All @@ -17,13 +18,13 @@ public function description(): ?string;

public function features(): void;

public function picture(): ?string;
public function picture(): ?Picture;

public function render(Config $config): Image;

public function title(): string;

public function url(): ?string;

public function watermark(): ?string;
public function watermark(): ?Picture;
}
5 changes: 3 additions & 2 deletions src/Layout/AbstractLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SimonHamp\TheOg\BorderPosition;
use SimonHamp\TheOg\Interfaces\Box as BoxInterface;
use SimonHamp\TheOg\Interfaces\Layout;
use SimonHamp\TheOg\Theme\Picture;
use SimonHamp\TheOg\Traits\RendersFeatures;

abstract class AbstractLayout implements Layout
Expand Down Expand Up @@ -56,7 +57,7 @@ public function description(): ?string
return $this->config->description ?? null;
}

public function picture(): ?string
public function picture(): ?Picture
{
return $this->config->picture ?? null;
}
Expand All @@ -75,7 +76,7 @@ public function url(): ?string
return parse_url($this->config->url, PHP_URL_HOST) ?? $this->config->url;
}

public function watermark(): ?string
public function watermark(): ?Picture
{
return $this->config->watermark ?? null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Layout/Layouts/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Avatar extends AbstractLayout
public function features(): void
{
$this->addFeature((new PictureBox())
->path($this->picture())
->path($this->picture()->path())
->circle()
->box(300, 300)
->position(
Expand All @@ -46,7 +46,7 @@ public function features(): void

if ($watermark = $this->watermark()) {
$this->addFeature((new PictureBox())
->path($watermark)
->path($watermark->path())
->box(100, 100)
->position(
x: 1180,
Expand Down
2 changes: 1 addition & 1 deletion src/Layout/Layouts/GitHubBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function features(): void

if ($watermark = $this->watermark()) {
$this->addFeature((new PictureBox())
->path($watermark)
->path($watermark->path())
->box(100, 100)
->position(
x: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/Layout/Layouts/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function features(): void

if ($watermark = $this->watermark()) {
$this->addFeature((new PictureBox())
->path($watermark)
->path($watermark->path())
->box(100, 100)
->position(
x: 0,
Expand Down
6 changes: 4 additions & 2 deletions src/Layout/Layouts/TwoUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SimonHamp\TheOg\Layout\PictureBox;
use SimonHamp\TheOg\Layout\Position;
use SimonHamp\TheOg\Layout\TextBox;
use SimonHamp\TheOg\Theme\PicturePlacement;

class TwoUp extends AbstractLayout
{
Expand All @@ -20,7 +21,8 @@ public function features(): void
{
if ($picture = $this->picture()) {
$this->addFeature((new PictureBox())
->path($picture)
->path($picture->path())
->placement($picture->placement() ?? PicturePlacement::Cover)
->box($this->width / 2, $this->height)
->position(
x: 0,
Expand Down Expand Up @@ -70,7 +72,7 @@ public function features(): void

if ($watermark = $this->watermark()) {
$this->addFeature((new PictureBox())
->path($watermark)
->path($watermark->path())
->box(100, 100)
->position(
x: 20,
Expand Down

0 comments on commit f84a5a0

Please sign in to comment.