Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use interfaces to allow for custom backgrounds and fonts #7

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ composer require simonhamp/the-og --with-all-dependencies
Using The OG is really simple. Here's a basic example:

```php
use SimonHamp\TheOg\Image;
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\Image;

(new Image())
->accentColor('#cc0000')
Expand Down Expand Up @@ -65,6 +65,7 @@ Themes are simple classes. You can create your own theme simply by extending the

```php
use SimonHamp\TheOg\Themes\AbstractTheme;
use SimonHamp\TheOg\Font;

$theme = new class(
accentColor: '#247BA0',
Expand Down
2 changes: 1 addition & 1 deletion src/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SimonHamp\TheOg;

enum Background: string
enum Background: string implements Interfaces\Background
{
case Bananas = 'bananas.webp';
case CloudyDay = 'cloudy-day.png';
Expand Down
4 changes: 2 additions & 2 deletions src/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace SimonHamp\TheOg;

enum Font: string
enum Font: string implements Interfaces\Font
{
case Inter = 'Inter/static/Inter-Regular.ttf';
case InterBlack = 'Inter/static/Inter-Black.ttf';
case InterBold = 'Inter/static/Inter-Bold.ttf';
case InterLight = 'Inter/static/Inter-Light.ttf';

public function path(): string
{
return __DIR__ . '/../resources/fonts/' . $this->value;
Expand Down
1 change: 1 addition & 0 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Intervention\Image\Image as RenderedImage;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Encoders\PngEncoder;
use SimonHamp\TheOg\Interfaces\Background;
use SimonHamp\TheOg\Interfaces\Layout;
use SimonHamp\TheOg\Layout\Layouts;
use SimonHamp\TheOg\Interfaces\Theme;
Expand Down
8 changes: 8 additions & 0 deletions src/Interfaces/Background.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace SimonHamp\TheOg\Interfaces;

interface Background
{
public function path(): string;
}
8 changes: 8 additions & 0 deletions src/Interfaces/Font.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace SimonHamp\TheOg\Interfaces;

interface Font
{
public function path(): string;
}
2 changes: 0 additions & 2 deletions src/Interfaces/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace SimonHamp\TheOg\Interfaces;

use Intervention\Image\Colors\Rgb\Color;
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\Font;

interface Theme
{
Expand Down
2 changes: 1 addition & 1 deletion src/Layout/TextBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Intervention\Image\Modifiers\TextModifier;
use Intervention\Image\Typography\FontFactory;
use Intervention\Image\Typography\TextBlock;
use SimonHamp\TheOg\Font;
use SimonHamp\TheOg\Interfaces\Font;
use SimonHamp\TheOg\Modifiers\TextModifier as CustomTextModifier;

readonly class TextBox extends Box
Expand Down
4 changes: 2 additions & 2 deletions src/Themes/AbstractTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace SimonHamp\TheOg\Themes;

use Intervention\Image\Colors\Rgb\Color;
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\Font;
use SimonHamp\TheOg\Interfaces\Background;
use SimonHamp\TheOg\Interfaces\Font;
use SimonHamp\TheOg\Interfaces\Theme;

abstract class AbstractTheme implements Theme
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/RendersFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Intervention\Image\Geometry\Point;
use Intervention\Image\Image;
use Intervention\Image\ImageManager;
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\Border;
use SimonHamp\TheOg\BorderPosition;
use SimonHamp\TheOg\Font;
use SimonHamp\TheOg\Image as Config;
use SimonHamp\TheOg\Interfaces\Background;
use SimonHamp\TheOg\Layout\TextBox;

trait RendersFeatures
Expand Down Expand Up @@ -89,7 +89,7 @@ protected function renderTextBox(TextBox $textBox): void
{
$textBox->render()->apply($this->canvas);
}

protected function renderBorder(): void
{
match ($this->border->getPosition()) {
Expand Down
Loading