Fixed: Get version of PDF

This commit is contained in:
philipp lang 2021-09-20 00:51:55 +02:00
parent f38a63e1f2
commit e02e74460f
2 changed files with 18 additions and 2 deletions

View File

@ -7,6 +7,7 @@ use Aweos\Resizer\Compressors\Factory as CompressorFactory;
use Aweos\Resizer\Lib\MediaPath;
use Aweos\Resizer\Models\Setting;
use Cache;
use Exception;
use Illuminate\Support\Collection;
use Media\Classes\MediaLibrary;
use Storage;
@ -41,7 +42,7 @@ class TagGenerator {
{
$filename = $this->path->filename();
$basePath = $this->path->versionsDirPath();
[$originalWidth, $originalHeight] = getimagesize($this->path->root());
[$originalWidth, $originalHeight] = $this->path->compressor()->originalSize();
$aspectRatio = $ratio === 'original'
? $originalWidth / $originalHeight
: $this->size($ratio)[0] / $this->size($ratio)[1];
@ -106,7 +107,7 @@ class TagGenerator {
$versions = $this->possibleFiles($ratio);
throw_unless(count($versions), Exception::class, "No files for {$path->root()} found");
throw_unless($versions && count($versions), Exception::class, "No files for {$path->root()} found");
return url($this->possibleFiles($ratio)->last()->get('url'));
}

View File

@ -38,6 +38,21 @@ class ImageTagTest extends TestCase
);
}
public function testFetchPdfImage()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', [100,200]);
$this->media->put('/pages/test.pdf', file_get_contents(__DIR__.'/stub/dummy.pdf'));
UploadedFile::fake()->image('test-500x500.pdf.jpg', 500, 500)->storeAs('uploads/public/c/pages', 'test-500x500.pdf.jpg', 'local');
UploadedFile::fake()->image('test-1275x1650.pdf.jpg', 1275, 1650)->storeAs('uploads/public/c/pages', 'test-1275x1650.pdf.jpg', 'local');
$this->assertEquals(
url("/storage/uploads/public/c/pages/test-1275x1650.pdf.jpg"),
app('resize')->biggestVersion('pages/test.pdf', 'original'),
);
}
public function testItGeneratesLazyLoadingTags()
{
Setting::set('folders', ['pages']);