From e02e74460ff78e4690e21790b8995b1d045072c8 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 20 Sep 2021 00:51:55 +0200 Subject: [PATCH] Fixed: Get version of PDF --- classes/TagGenerator.php | 5 +++-- tests/ImageTagTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/classes/TagGenerator.php b/classes/TagGenerator.php index 4b58add..950c702 100644 --- a/classes/TagGenerator.php +++ b/classes/TagGenerator.php @@ -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')); } diff --git a/tests/ImageTagTest.php b/tests/ImageTagTest.php index bb8dda9..bda3648 100644 --- a/tests/ImageTagTest.php +++ b/tests/ImageTagTest.php @@ -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']);