|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Services; |
| 4 | + |
| 5 | +use Intervention\Image\Colors\Rgb\Color; |
| 6 | +use SimonHamp\TheOg\BorderPosition; |
| 7 | +use SimonHamp\TheOg\Layout\Layouts\Standard; |
| 8 | +use SimonHamp\TheOg\Layout\PictureBox; |
| 9 | +use SimonHamp\TheOg\Layout\Position; |
| 10 | +use SimonHamp\TheOg\Layout\TextBox; |
| 11 | + |
| 12 | +class NativePhpLayout extends Standard |
| 13 | +{ |
| 14 | + protected BorderPosition $borderPosition = BorderPosition::All; |
| 15 | + |
| 16 | + protected int $borderWidth = 2; |
| 17 | + |
| 18 | + protected int $height = 630; |
| 19 | + |
| 20 | + protected int $padding = 40; |
| 21 | + |
| 22 | + protected int $width = 1200; |
| 23 | + |
| 24 | + public function features(): void |
| 25 | + { |
| 26 | + $this->addFeature((new TextBox) |
| 27 | + ->name('title') |
| 28 | + ->text($this->title()) |
| 29 | + ->color($this->config->theme->getTitleColor()) |
| 30 | + ->font($this->config->theme->getTitleFont()) |
| 31 | + ->size(60) |
| 32 | + ->box($this->mountArea()->box->width(), 400) |
| 33 | + ->position( |
| 34 | + x: 0, |
| 35 | + y: 0, |
| 36 | + relativeTo: function () { |
| 37 | + if ($url = $this->getFeature('url')) { |
| 38 | + return $url->anchor(Position::BottomLeft)->moveY(25); |
| 39 | + } |
| 40 | + |
| 41 | + return $this->mountArea()->anchor()->moveY(20); |
| 42 | + } |
| 43 | + ) |
| 44 | + ); |
| 45 | + |
| 46 | + if ($description = $this->description()) { |
| 47 | + $this->addFeature((new TextBox) |
| 48 | + ->name('description') |
| 49 | + ->text($description) |
| 50 | + ->color($this->config->theme->getDescriptionColor()) |
| 51 | + ->font($this->config->theme->getDescriptionFont()) |
| 52 | + ->size(40) |
| 53 | + ->box($this->mountArea()->box->width(), 240) |
| 54 | + ->position( |
| 55 | + x: 0, |
| 56 | + y: 50, |
| 57 | + relativeTo: fn () => $this->getFeature('title')->anchor(Position::BottomLeft), |
| 58 | + ) |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + if ($url = $this->url()) { |
| 63 | + $this->addFeature((new TextBox) |
| 64 | + ->name('url') |
| 65 | + ->text($url) |
| 66 | + ->color(new Color(0, 170, 166)) |
| 67 | + ->font($this->config->theme->getUrlFont()) |
| 68 | + ->size(28) |
| 69 | + ->box($this->mountArea()->box->width(), 45) |
| 70 | + ->position( |
| 71 | + x: 0, |
| 72 | + y: 20, |
| 73 | + relativeTo: fn () => $this->mountArea()->anchor(), |
| 74 | + ) |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + if ($watermark = $this->watermark()) { |
| 79 | + $this->addFeature((new PictureBox) |
| 80 | + ->path($watermark->path()) |
| 81 | + ->box(200, 200) // Doubled from 100x100 to 200x200 |
| 82 | + ->position( |
| 83 | + x: 0, |
| 84 | + y: 0, |
| 85 | + relativeTo: fn () => $this->mountArea()->anchor(Position::BottomRight), |
| 86 | + anchor: Position::BottomRight |
| 87 | + ) |
| 88 | + ); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + public function url(): string |
| 93 | + { |
| 94 | + if ($url = parent::url()) { |
| 95 | + return strtoupper($url); |
| 96 | + } |
| 97 | + |
| 98 | + return ''; |
| 99 | + } |
| 100 | +} |
0 commit comments