Skip to content

Commit

Permalink
Merge pull request #15 from visuellverstehen/provide-acces-to-the-asset
Browse files Browse the repository at this point in the history
Provide getAsset method
  • Loading branch information
simonerd authored Mar 4, 2024
2 parents 948dfc5 + 3e7e0ba commit 246e293
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Picturesque.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(Asset|string $asset, ?Context $tagContext = null)

$this->setupGlide($tagContext);
}

public function alt(string $text): self
{
$this->options->put('alt', $text);
Expand Down Expand Up @@ -135,6 +135,11 @@ public function generate(): self

return $this;
}

public function getAsset(): Asset
{
return $this->asset;
}

public function html(): string
{
Expand Down Expand Up @@ -176,7 +181,7 @@ public function html(): string

public function isGlideSupportedFiletype(): bool|null
{
if (! $this->asset) {
if (! $this->getAsset()) {
return null;
}

Expand Down Expand Up @@ -240,7 +245,7 @@ private function calcRatio(string $ratio): float|string

private function evaluateFiletype(): string
{
$meta = $this->asset->meta();
$meta = $this->getAsset()->meta();

if (! $meta ||
! array_key_exists('mime_type', $meta) ||
Expand Down Expand Up @@ -281,7 +286,7 @@ private function filetypes(): array
private function makeAlt(): string
{
if (($alt = $this->options->get('alt')) ||
($alt = $this->asset->data()->get('alt'))) {
($alt = $this->getAsset()->data()->get('alt'))) {
$alt = strip_tags($alt);

if (config('picturesque.alt_fullstop')) {
Expand Down Expand Up @@ -324,7 +329,7 @@ private function makeImg()
];

if (! $this->isGlideSupportedFiletype()) {
$img['src'] = $this->asset->url();
$img['src'] = $this->getAsset()->url();
} else {
$img['src'] = $this->makeGlideUrl(['width' => $this->smallestSrc(), 'fit' => 'crop_focal']);
}
Expand All @@ -341,12 +346,12 @@ private function makeImg()
}

// width
if ($w = $this->asset->width()) {
if ($w = $this->getAsset()->width()) {
$img['width'] = (int) round($w);
}

// height
if ($h = $this->asset->height()) {
if ($h = $this->getAsset()->height()) {
$img['height'] = (int) round($h);
}

Expand Down Expand Up @@ -543,7 +548,7 @@ private function parseSizeData(string $sizeData, float|string $ratio = 'auto'):
*/
private function setupGlide(?Context $context = null)
{
$this->glideSource = ['src' => $this->asset];
$this->glideSource = ['src' => $this->getAsset()];
$this->evaluateFiletype();

if (! $context) {
Expand Down

0 comments on commit 246e293

Please sign in to comment.