Fixed: Get version of PDF
This commit is contained in:
parent
f38a63e1f2
commit
e02e74460f
|
@ -7,6 +7,7 @@ use Aweos\Resizer\Compressors\Factory as CompressorFactory;
|
||||||
use Aweos\Resizer\Lib\MediaPath;
|
use Aweos\Resizer\Lib\MediaPath;
|
||||||
use Aweos\Resizer\Models\Setting;
|
use Aweos\Resizer\Models\Setting;
|
||||||
use Cache;
|
use Cache;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Media\Classes\MediaLibrary;
|
use Media\Classes\MediaLibrary;
|
||||||
use Storage;
|
use Storage;
|
||||||
|
@ -41,7 +42,7 @@ class TagGenerator {
|
||||||
{
|
{
|
||||||
$filename = $this->path->filename();
|
$filename = $this->path->filename();
|
||||||
$basePath = $this->path->versionsDirPath();
|
$basePath = $this->path->versionsDirPath();
|
||||||
[$originalWidth, $originalHeight] = getimagesize($this->path->root());
|
[$originalWidth, $originalHeight] = $this->path->compressor()->originalSize();
|
||||||
$aspectRatio = $ratio === 'original'
|
$aspectRatio = $ratio === 'original'
|
||||||
? $originalWidth / $originalHeight
|
? $originalWidth / $originalHeight
|
||||||
: $this->size($ratio)[0] / $this->size($ratio)[1];
|
: $this->size($ratio)[0] / $this->size($ratio)[1];
|
||||||
|
@ -106,7 +107,7 @@ class TagGenerator {
|
||||||
|
|
||||||
$versions = $this->possibleFiles($ratio);
|
$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'));
|
return url($this->possibleFiles($ratio)->last()->get('url'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
public function testItGeneratesLazyLoadingTags()
|
||||||
{
|
{
|
||||||
Setting::set('folders', ['pages']);
|
Setting::set('folders', ['pages']);
|
||||||
|
|
Loading…
Reference in New Issue