Skip to content

Commit

Permalink
Support different placements
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Jan 16, 2024
1 parent f84a5a0 commit 148be09
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Layout/PictureBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
use ImagickPixel;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
use SimonHamp\TheOg\Theme\PicturePlacement;

class PictureBox extends Box
class PictureBox extends Box
{
public string $path;

/**
* @var array<callable<Imagick>>
*/
public array $maskQueue;

public string $path;

public PicturePlacement $placement = PicturePlacement::Natural;

protected ImageInterface $picture;

public function render(ImageInterface $image): void
Expand Down Expand Up @@ -71,16 +74,28 @@ public function circle(): static
return $this;
}

public function path(string $path): self
public function path(string $path): static
{
$this->path = $path;
return $this;
}

public function placement(PicturePlacement $placement): static
{
$this->placement = $placement;
return $this;
}

protected function getPicture(): ImageInterface
{
return $this->picture ??= ImageManager::imagick()
->read(file_get_contents($this->path))
->cover($this->box->width(), $this->box->height());
$this->picture ??= ImageManager::imagick()
->read(file_get_contents($this->path));

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())),
};

return $this->picture;
}
}

0 comments on commit 148be09

Please sign in to comment.