Skip to content

Commit

Permalink
Disabled tiny placeholder generation when use_tiny_placeholder config…
Browse files Browse the repository at this point in the history
… is disabled (#3513)

* Disabled tiny placeholder generation when use_tiny_placeholder config is disabled

* Conversion specific Width Calculator is supported

* Conversion specific Width Calculator is supported

* Revert "Conversion specific Width Calculator is supported"

This reverts commit 2864d0b.

* Revert "Conversion specific Width Calculator is supported"

This reverts commit f102ebf.

---------

Co-authored-by: jhorie <jhorie@mynober.nl>
  • Loading branch information
jhorie and jhorie committed Jan 24, 2024
1 parent de8cb1a commit 4ad51b5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/media-library.php
Expand Up @@ -225,6 +225,7 @@
/*
* By default rendering media to a responsive image will add some javascript and a tiny placeholder.
* This ensures that the browser can already determine the correct layout.
* When disabled, no tiny placeholder is generated.
*/
'use_tiny_placeholders' => true,

Expand Down
4 changes: 4 additions & 0 deletions src/ResponsiveImages/ResponsiveImageGenerator.php
Expand Up @@ -117,6 +117,10 @@ public function generateTinyJpg(
string $conversionName,
BaseTemporaryDirectory $temporaryDirectory
): void {
if (! config('media-library.responsive_images.use_tiny_placeholders')) {
return;
}

$tempDestination = $temporaryDirectory->path('tiny.jpg');

$this->tinyPlaceholderGenerator->generateTinyPlaceholder($originalImagePath, $tempDestination);
Expand Down
26 changes: 26 additions & 0 deletions tests/ResponsiveImages/ResponsiveImageGeneratorTest.php
Expand Up @@ -86,3 +86,29 @@
$this->artisan('media-library:regenerate');
expect($media->fresh()->responsive_images['thumb']['urls'])->toHaveCount(1);
});

it('will generate tiny placeholders when tiny placeholders are turned on', function () {
$media = $this->testModelWithConversion
->addMedia($this->getTestJpg())
->withResponsiveImages()
->toMediaCollection();

$responsiveImage = $media->refresh()->responsive_images;

expect($responsiveImage['media_library_original'])->toHaveKey('base64svg');

expect((string) $responsiveImage['media_library_original']['base64svg'])->toContain('data:image/svg+xml;base64,');
});

it('will not generate tiny placeholders when tiny placeholders are turned off', function () {
config()->set('media-library.responsive_images.use_tiny_placeholders', false);

$media = $this->testModelWithConversion
->addMedia($this->getTestJpg())
->withResponsiveImages()
->toMediaCollection();

$responsiveImage = $media->refresh()->responsive_images;

expect($responsiveImage['media_library_original'])->not()->toHaveKey('base64svg');
});

0 comments on commit 4ad51b5

Please sign in to comment.