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
8 changes: 8 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public function bindGlide()
new Flysystem(new LocalFilesystemAdapter($this->config['destination'].'/'.$directory))
);

// Point the glide cache disk to the same location, so that anything
// reading generated images back (e.g. the glide:data_url tag) will
// find them where the server wrote them.
config([
'statamic.assets.image_manipulation.cache' => true,
'statamic.assets.image_manipulation.cache_path' => $this->config['destination'].'/'.$directory,
]);

$this->app->bind(UrlBuilder::class, function () use ($directory) {
return new StaticUrlBuilder($this->app[ImageGenerator::class], [
'route' => URL::tidy($this->config['base_url'].'/'.$directory),
Expand Down
28 changes: 28 additions & 0 deletions tests/GenerateGlideDataUrlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tests;

use PHPUnit\Framework\Attributes\Test;
use Tests\Concerns\RunsGeneratorCommand;

class GenerateGlideDataUrlTest extends TestCase
{
use RunsGeneratorCommand;

const ONE_PIXEL_PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';

#[Test]
public function it_generates_data_urls_by_reading_images_from_the_static_glide_cache()
{
$this->files->put(public_path('image.png'), base64_decode(self::ONE_PIXEL_PNG));

$this->files->put(
base_path('resources/views/articles/show.antlers.html'),
'<img src="{{ glide:data_url src="/image.png" width="50" }}">'
);

$files = $this->generate();

$this->assertStringContainsString('src="data:image/png;base64,', $files['articles/one/index.html']);
}
}