diff --git a/src/Interfaces/Layout.php b/src/Interfaces/Layout.php index 8c0d964..e9db685 100644 --- a/src/Interfaces/Layout.php +++ b/src/Interfaces/Layout.php @@ -24,4 +24,6 @@ public function render(Config $config): Image; public function title(): string; public function url(): ?string; + + public function watermark(): ?string; } diff --git a/src/Layout/AbstractLayout.php b/src/Layout/AbstractLayout.php index f72ad69..bd7d6e2 100644 --- a/src/Layout/AbstractLayout.php +++ b/src/Layout/AbstractLayout.php @@ -75,6 +75,11 @@ public function url(): ?string return parse_url($this->config->url, PHP_URL_HOST) ?? $this->config->url; } + public function watermark(): ?string + { + return $this->config->watermark ?? null; + } + /** * The area within the canvas that we should be rendering content. This is just a convenience object to help layout * of other features and is not normally rendered (it's not added to the $features list) diff --git a/src/Layout/Layouts/Avatar.php b/src/Layout/Layouts/Avatar.php index 5a98b88..3673448 100644 --- a/src/Layout/Layouts/Avatar.php +++ b/src/Layout/Layouts/Avatar.php @@ -43,6 +43,18 @@ public function features(): void anchor: Position::MiddleTop, ) ); + + if ($watermark = $this->watermark()) { + $this->addFeature((new PictureBox()) + ->path($watermark) + ->box(100, 100) + ->position( + x: 1180, + y: 610, + anchor: Position::BottomRight + ) + ); + } } public function url(): string diff --git a/src/Layout/Layouts/GitHubBasic.php b/src/Layout/Layouts/GitHubBasic.php index 0dd8739..3ef48d3 100644 --- a/src/Layout/Layouts/GitHubBasic.php +++ b/src/Layout/Layouts/GitHubBasic.php @@ -4,6 +4,7 @@ use SimonHamp\TheOg\BorderPosition; use SimonHamp\TheOg\Layout\AbstractLayout; +use SimonHamp\TheOg\Layout\PictureBox; use SimonHamp\TheOg\Layout\Position; use SimonHamp\TheOg\Layout\TextBox; @@ -90,5 +91,18 @@ public function features(): void ) ); } + + if ($watermark = $this->watermark()) { + $this->addFeature((new PictureBox()) + ->path($watermark) + ->box(100, 100) + ->position( + x: 0, + y: 0, + relativeTo: fn () => $this->mountArea()->anchor(Position::BottomRight), + anchor: Position::BottomRight + ) + ); + } } } diff --git a/src/Layout/Layouts/Standard.php b/src/Layout/Layouts/Standard.php index 03d371c..2f092e0 100644 --- a/src/Layout/Layouts/Standard.php +++ b/src/Layout/Layouts/Standard.php @@ -4,6 +4,7 @@ use SimonHamp\TheOg\BorderPosition; use SimonHamp\TheOg\Layout\AbstractLayout; +use SimonHamp\TheOg\Layout\PictureBox; use SimonHamp\TheOg\Layout\Position; use SimonHamp\TheOg\Layout\TextBox; @@ -89,6 +90,19 @@ public function features(): void ) ); } + + if ($watermark = $this->watermark()) { + $this->addFeature((new PictureBox()) + ->path($watermark) + ->box(100, 100) + ->position( + x: 0, + y: 0, + relativeTo: fn () => $this->mountArea()->anchor(Position::BottomRight), + anchor: Position::BottomRight + ) + ); + } } // XXX: This feels weird... maybe it should happen in the theme? Or let the content decide? diff --git a/src/Layout/Layouts/TwoUp.php b/src/Layout/Layouts/TwoUp.php index ffd0e68..047d6b3 100644 --- a/src/Layout/Layouts/TwoUp.php +++ b/src/Layout/Layouts/TwoUp.php @@ -67,6 +67,18 @@ public function features(): void anchor: Position::BottomRight, ) ); + + if ($watermark = $this->watermark()) { + $this->addFeature((new PictureBox()) + ->path($watermark) + ->box(100, 100) + ->position( + x: 20, + y: 610, + anchor: Position::BottomLeft + ) + ); + } } if ($url = $this->url()) { diff --git a/tests/Integration/ImageTest.php b/tests/Integration/ImageTest.php index 9b5da5f..0d0894a 100644 --- a/tests/Integration/ImageTest.php +++ b/tests/Integration/ImageTest.php @@ -52,6 +52,15 @@ public static function snapshotImages(): iterable 'more-text-features', ]; + yield 'with watermark' => [ + (new Image()) + ->url('https://example.com/blog/some-blog-post-url') + ->title('Some blog post title that is quite big and quite long') + ->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words') + ->watermark(__DIR__.'/../resources/logo.png'), + 'with-watermark', + ]; + yield 'different theme' => [ (new Image()) ->theme(Theme::Dark) @@ -109,7 +118,8 @@ public static function snapshotImages(): iterable ->layout(new GitHubBasic) ->url('username/repo') ->title('An awesome package') - ->background(BuiltInBackground::CloudyDay, 0.8), + ->background(BuiltInBackground::CloudyDay, 0.8) + ->watermark(__DIR__.'/../resources/logo.png'), 'githubbasic-layout', ]; @@ -126,7 +136,8 @@ public static function snapshotImages(): iterable ->url('https://my-ecommerce-store.com/') ->title('This layout is great for eCommerce!') ->callToAction('Buy Now →') - ->background(BuiltInBackground::CloudyDay, 0.8), + ->background(BuiltInBackground::CloudyDay, 0.8) + ->watermark(__DIR__.'/../resources/logo.png'), 'twoup-layout', ]; @@ -177,7 +188,8 @@ public static function snapshotImages(): iterable ->layout(new Avatar) ->accentColor('#003') ->picture('https://i.pravatar.cc/300?img=10') - ->title('Simone Hampstead'), + ->title('Simone Hampstead') + ->watermark(__DIR__.'/../resources/logo.png'), 'avatar-layout', ]; } diff --git a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set avatar layout__1.png b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set avatar layout__1.png index 9f13fe2..614bd71 100644 Binary files a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set avatar layout__1.png and b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set avatar layout__1.png differ diff --git a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set github layout__1.png b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set github layout__1.png index ed3add4..45bba4b 100644 Binary files a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set github layout__1.png and b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set github layout__1.png differ diff --git a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set twoup layout__1.png b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set twoup layout__1.png index a51d273..d0e88b7 100644 Binary files a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set twoup layout__1.png and b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set twoup layout__1.png differ diff --git a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set with watermark__1.png b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set with watermark__1.png new file mode 100644 index 0000000..ad62a76 Binary files /dev/null and b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set with watermark__1.png differ diff --git a/tests/resources/logo.png b/tests/resources/logo.png new file mode 100644 index 0000000..1e789d9 Binary files /dev/null and b/tests/resources/logo.png differ