Skip to content

Commit 4c4fb26

Browse files
committed
Fix image placement
1 parent 70d099b commit 4c4fb26

File tree

5 files changed

+145
-1
lines changed

5 files changed

+145
-1
lines changed

src/Layout/PictureBox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function getPicture(): ImageInterface
9494

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

100100
return $this->picture;

tests/Integration/ImageTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,18 @@ public static function snapshotImages(): iterable
208208
->title('Adding Unique Field to MySQL Table With Existing Records'),
209209
'tricky-title-truncation',
210210
];
211+
212+
yield 'very wide image' => [
213+
(new Image())
214+
->layout(
215+
(new ShiftLayout)
216+
->setCategory('Testing')
217+
->setReadTime(11)
218+
)
219+
->title('A Simple Title')
220+
->url('https://shifty.com/')
221+
->watermark(__DIR__.'/../resources/logo.png'),
222+
'very-wide-image',
223+
];
211224
}
212225
}

tests/Integration/ShiftLayout.php

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
namespace Tests\Integration;
4+
5+
use SimonHamp\TheOg\BorderPosition;
6+
use SimonHamp\TheOg\Layout\AbstractLayout;
7+
use SimonHamp\TheOg\Layout\PictureBox;
8+
use SimonHamp\TheOg\Layout\Position;
9+
use SimonHamp\TheOg\Layout\TextBox;
10+
11+
class ShiftLayout extends AbstractLayout
12+
{
13+
protected BorderPosition $borderPosition = BorderPosition::None;
14+
15+
protected int $borderWidth = 0;
16+
17+
protected int $height = 640;
18+
19+
protected int $padding = 10;
20+
21+
protected int $width = 1280;
22+
23+
protected string $category;
24+
25+
protected int $readTime;
26+
27+
public function features(): void
28+
{
29+
$this->addFeature((new PictureBox)
30+
->path(__DIR__.'/../resources/very-wide.png')
31+
->box(2297, 49)
32+
->position(
33+
x: 0,
34+
y: 0,
35+
)
36+
);
37+
38+
$this->addFeature((new TextBox)
39+
->name('category')
40+
->text($this->category())
41+
->color($this->config->theme->getUrlColor())
42+
->font($this->config->theme->getUrlFont())
43+
->size(28)
44+
->box(300, 45)
45+
->position(
46+
x: 0,
47+
y: 60,
48+
)
49+
);
50+
51+
$this->addFeature((new TextBox)
52+
->name('title')
53+
->text($this->title())
54+
->color($this->config->theme->getTitleColor())
55+
->font($this->config->theme->getTitleFont())
56+
->size(60)
57+
->box($this->mountArea()->box->width(), 400)
58+
->position(
59+
x: 0,
60+
y: 20,
61+
relativeTo: fn () => $this->getFeature('category')->anchor(Position::BottomLeft)
62+
)
63+
);
64+
65+
if ($readTime = $this->readTime()) {
66+
$this->addFeature((new TextBox)
67+
->name('read-time')
68+
->text($readTime.' minute read')
69+
->color($this->config->theme->getCallToActionColor())
70+
->font($this->config->theme->getCallToActionFont())
71+
->size(20)
72+
->box(300, 45)
73+
->position(
74+
x: 0,
75+
y: 20,
76+
relativeTo: fn () => $this->getFeature('title')->anchor(Position::BottomLeft)
77+
)
78+
);
79+
}
80+
81+
$this->addFeature((new TextBox)
82+
->name('url')
83+
->text($this->url())
84+
->color($this->config->theme->getUrlColor())
85+
->font($this->config->theme->getUrlFont())
86+
->size(28)
87+
->box($this->mountArea()->box->width(), 45)
88+
->position(
89+
x: 0,
90+
y: 0,
91+
relativeTo: fn () => $this->mountArea()->anchor(Position::BottomLeft),
92+
anchor: Position::BottomLeft
93+
)
94+
);
95+
96+
$this->addFeature((new PictureBox)
97+
->path($this->watermark()->path())
98+
->box(100, 100)
99+
->position(
100+
x: 0,
101+
y: 0,
102+
relativeTo: fn () => $this->mountArea()->anchor(Position::BottomRight),
103+
anchor: Position::BottomRight
104+
)
105+
);
106+
}
107+
108+
public function category(): string
109+
{
110+
return $this->category;
111+
}
112+
113+
public function readTime(): ?int
114+
{
115+
return $this->readTime ?? null;
116+
}
117+
118+
public function setCategory(string $category): static
119+
{
120+
$this->category = $category;
121+
122+
return $this;
123+
}
124+
125+
public function setReadTime(int $readTime): static
126+
{
127+
$this->readTime = $readTime;
128+
129+
return $this;
130+
}
131+
}

tests/resources/very-wide.png

45.3 KB
Loading

0 commit comments

Comments
 (0)