Skip to content
Open
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
13 changes: 11 additions & 2 deletions src/Tags/Glide.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Statamic\Facades\Image;
use Statamic\Facades\Path;
use Statamic\Facades\URL;
use Statamic\Imaging\AssetNotFoundException;
use Statamic\Imaging\ImageGenerator;
use Statamic\Support\Str;

Expand Down Expand Up @@ -177,7 +178,15 @@ private function generateImage($item)
: $this->getGenerator()->generateByPath($item, $params);
}

return $this->getGenerator()->generateByAsset(Asset::find($item), $params);
$asset = $item instanceof AssetContract ? $item : Asset::find($item);

if (! $asset) {
throw new AssetNotFoundException(
sprintf('Could not generate a manipulated image from asset [%s]', $item)
);
}

return $this->getGenerator()->generateByAsset($asset, $params);
}

/**
Expand Down Expand Up @@ -290,7 +299,7 @@ private function normalizeItem($item)

// Double colons indicate an asset ID.
if (Str::contains($item, '::')) {
return Asset::find($item);
return Asset::find($item) ?? $item;
}

// In a subfolder installation, the subfolder will likely be passed in
Expand Down
25 changes: 25 additions & 0 deletions tests/Tags/GlideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ public function it_outputs_an_absolute_url_when_the_url_does_not_have_a_valid_ex
$this->assertSame('https://statamic.com/foo', $parse);
}

#[Test]
public function it_doesnt_error_when_a_url_cannot_be_resolved_to_an_asset()
{
$tag = '{{ glide src="http://external.com/bar (1).jpg" width="100" }}{{ url }}{{ /glide }}';

$this->assertSame('', (string) Parse::template($tag, trusted: true));
}

#[Test]
public function it_doesnt_error_when_an_asset_id_cannot_be_resolved()
{
$tag = '{{ glide src="test::bar.jpg" width="100" fit="crop_focal" }}{{ url }}{{ /glide }}';

$this->assertSame('', (string) Parse::template($tag, trusted: true));
}

#[Test]
#[DefineEnvironment('relativeRouteUrl')]
public function it_doesnt_error_when_an_asset_id_cannot_be_resolved_and_images_are_served_directly()
{
$tag = '{{ glide src="test::bar.jpg" width="100" }}{{ url }}{{ /glide }}';

$this->assertSame('', (string) Parse::template($tag, trusted: true));
}

#[Test]
public function it_outputs_a_data_url()
{
Expand Down
Loading