Skip to content

Commit 3d9a8ec

Browse files
mynetxclaude
andcommitted
Fix glide:data_url reading from the wrong glide cache during generation
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 089ea29 commit 3d9a8ec

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/Generator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ public function bindGlide()
128128
new Flysystem(new LocalFilesystemAdapter($this->config['destination'].'/'.$directory))
129129
);
130130

131+
// Point the glide cache disk to the same location, so that anything
132+
// reading generated images back (e.g. the glide:data_url tag) will
133+
// find them where the server wrote them.
134+
config([
135+
'statamic.assets.image_manipulation.cache' => true,
136+
'statamic.assets.image_manipulation.cache_path' => $this->config['destination'].'/'.$directory,
137+
]);
138+
131139
$this->app->bind(UrlBuilder::class, function () use ($directory) {
132140
return new StaticUrlBuilder($this->app[ImageGenerator::class], [
133141
'route' => URL::tidy($this->config['base_url'].'/'.$directory),

tests/GenerateGlideDataUrlTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use Tests\Concerns\RunsGeneratorCommand;
7+
8+
class GenerateGlideDataUrlTest extends TestCase
9+
{
10+
use RunsGeneratorCommand;
11+
12+
const ONE_PIXEL_PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
13+
14+
#[Test]
15+
public function it_generates_data_urls_by_reading_images_from_the_static_glide_cache()
16+
{
17+
$this->files->put(public_path('image.png'), base64_decode(self::ONE_PIXEL_PNG));
18+
19+
$this->files->put(
20+
base_path('resources/views/articles/show.antlers.html'),
21+
'<img src="{{ glide:data_url src="/image.png" width="50" }}">'
22+
);
23+
24+
$files = $this->generate();
25+
26+
$this->assertStringContainsString('src="data:image/png;base64,', $files['articles/one/index.html']);
27+
}
28+
}

0 commit comments

Comments
 (0)