Fixed: Dont generate versions for SVG

This commit is contained in:
Philipp Lang 2021-09-06 13:03:38 +02:00
parent 15a4046402
commit 341349848d
4 changed files with 37 additions and 1 deletions

View File

@ -78,7 +78,7 @@ class TagGenerator {
$files = $this->possibleFiles($ratio);
if ($files->isEmpty()) {
return 'src="/storage/app/media/'.$path.'"';
return 'src="'.$this->media->findFiles($path)[0]->publicUrl.'"';
}
$sizes = $files->map(function($file) {

View File

@ -85,4 +85,25 @@ class ImageTagTest extends TestCase
));
}
public function testPickOriginalImageWhenSvgIsGiven()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', [['name' => 'size', 'aspect_ratio' => '1200x280']]);
Setting::set('breakpoints', [640]);
$this->media->put('/pages/test.svg', file_get_contents(__DIR__.'/stub/close.svg'));
$this->assertFalse(str_contains(
app(TagGenerator::class)->generate('pages/test.svg', 'size'),
'srcset',
));
$this->assertFalse(str_contains(
app(TagGenerator::class)->generate('pages/test.svg', 'size'),
'sizes',
));
$this->assertTrue(str_contains(
app(TagGenerator::class)->generate('pages/test.svg', 'size'),
'src="'.$this->media->findFiles('/pages/test.svg')[0]->publicUrl.'"',
));
}
}

View File

@ -155,4 +155,18 @@ class ResizerTest extends TestCase
$this->assertHasFile('pages/neu/test-100x80.jpg');
}
public function testDontGenerateSvgImage(): void
{
Setting::set('folders', [['folder' => '/pages']]);
Setting::set('sizes', []);
Setting::set('breakpoints', ['100']);
$file = UploadedFile::fake()->image('test.jpg', 500, 400);
$media = MediaLibrary::instance();
$media->put('/pages/test.svg', file_get_contents(__DIR__.'/stub/close.svg'));
Event::fire('media.file.upload', [null, '/pages/test.svg', null]);
$this->assertFileCount(0, 'pages/neu');
}
}

1
tests/stub/close.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M10 8.586L2.929 1.515 1.515 2.929 8.586 10l-7.071 7.071 1.414 1.414L10 11.414l7.071 7.071 1.414-1.414L11.414 10l7.071-7.071-1.414-1.414L10 8.586z"/></svg>

After

Width:  |  Height:  |  Size: 224 B