Skip to content

Commit

Permalink
Fix image placement
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Oct 6, 2024
1 parent 70d099b commit 4c4fb26
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Layout/PictureBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function getPicture(): ImageInterface

match ($this->placement) {
PicturePlacement::Cover => $this->picture->cover($this->box->width(), $this->box->height()),
PicturePlacement::Natural => $this->picture->scaleDown(min($this->box->width(), $this->box->height())),
PicturePlacement::Natural => $this->picture->scaleDown($this->box->width(), $this->box->height()),
};

return $this->picture;
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,18 @@ public static function snapshotImages(): iterable
->title('Adding Unique Field to MySQL Table With Existing Records'),
'tricky-title-truncation',
];

yield 'very wide image' => [
(new Image())
->layout(
(new ShiftLayout)
->setCategory('Testing')
->setReadTime(11)
)
->title('A Simple Title')
->url('https://shifty.com/')
->watermark(__DIR__.'/../resources/logo.png'),
'very-wide-image',
];
}
}
131 changes: 131 additions & 0 deletions tests/Integration/ShiftLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace Tests\Integration;

use SimonHamp\TheOg\BorderPosition;
use SimonHamp\TheOg\Layout\AbstractLayout;
use SimonHamp\TheOg\Layout\PictureBox;
use SimonHamp\TheOg\Layout\Position;
use SimonHamp\TheOg\Layout\TextBox;

class ShiftLayout extends AbstractLayout
{
protected BorderPosition $borderPosition = BorderPosition::None;

protected int $borderWidth = 0;

protected int $height = 640;

protected int $padding = 10;

protected int $width = 1280;

protected string $category;

protected int $readTime;

public function features(): void
{
$this->addFeature((new PictureBox)
->path(__DIR__.'/../resources/very-wide.png')
->box(2297, 49)
->position(
x: 0,
y: 0,
)
);

$this->addFeature((new TextBox)
->name('category')
->text($this->category())
->color($this->config->theme->getUrlColor())
->font($this->config->theme->getUrlFont())
->size(28)
->box(300, 45)
->position(
x: 0,
y: 60,
)
);

$this->addFeature((new TextBox)
->name('title')
->text($this->title())
->color($this->config->theme->getTitleColor())
->font($this->config->theme->getTitleFont())
->size(60)
->box($this->mountArea()->box->width(), 400)
->position(
x: 0,
y: 20,
relativeTo: fn () => $this->getFeature('category')->anchor(Position::BottomLeft)
)
);

if ($readTime = $this->readTime()) {
$this->addFeature((new TextBox)
->name('read-time')
->text($readTime.' minute read')
->color($this->config->theme->getCallToActionColor())
->font($this->config->theme->getCallToActionFont())
->size(20)
->box(300, 45)
->position(
x: 0,
y: 20,
relativeTo: fn () => $this->getFeature('title')->anchor(Position::BottomLeft)
)
);
}

$this->addFeature((new TextBox)
->name('url')
->text($this->url())
->color($this->config->theme->getUrlColor())
->font($this->config->theme->getUrlFont())
->size(28)
->box($this->mountArea()->box->width(), 45)
->position(
x: 0,
y: 0,
relativeTo: fn () => $this->mountArea()->anchor(Position::BottomLeft),
anchor: Position::BottomLeft
)
);

$this->addFeature((new PictureBox)
->path($this->watermark()->path())
->box(100, 100)
->position(
x: 0,
y: 0,
relativeTo: fn () => $this->mountArea()->anchor(Position::BottomRight),
anchor: Position::BottomRight
)
);
}

public function category(): string
{
return $this->category;
}

public function readTime(): ?int
{
return $this->readTime ?? null;
}

public function setCategory(string $category): static
{
$this->category = $category;

return $this;
}

public function setReadTime(int $readTime): static
{
$this->readTime = $readTime;

return $this;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/resources/very-wide.png
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 4c4fb26

Please sign in to comment.