From 5cb79c75a6ef7baaa0fcbc6983e2e6ee32475983 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Fri, 17 Sep 2021 12:28:41 +0000 Subject: [PATCH] Fixed: Create versions of PDF image --- compressors/PdfCompressor.php | 4 ++-- tests/ResizerTest.php | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compressors/PdfCompressor.php b/compressors/PdfCompressor.php index f1185c3..595a8c4 100644 --- a/compressors/PdfCompressor.php +++ b/compressors/PdfCompressor.php @@ -10,7 +10,7 @@ class PdfCompressor extends Compressor { protected function getExtension(): string { - return 'jpg'; + return 'pdf.jpg'; } public function make(string $path): array @@ -28,7 +28,7 @@ class PdfCompressor extends Compressor { private function extractImage(string $pdf): string { - $file = $this->tmpPath().'.jpg'; + $file = $this->tmpPath().'.'.$this->getExtension(); exec('convert -density 150 '.escapeshellarg($pdf.'[0]').' -quality 90 '.escapeshellarg($file), $output, $r); diff --git a/tests/ResizerTest.php b/tests/ResizerTest.php index be0e6c3..bb440d6 100644 --- a/tests/ResizerTest.php +++ b/tests/ResizerTest.php @@ -192,6 +192,7 @@ class ResizerTest extends TestCase Event::fire('media.file.upload', [null, '/pages/test.png', null]); $this->assertHasFile('pages/test-100x100.png'); + $this->assertHasFile('pages/test-500x500.png'); $this->assertFileCount(2, 'pages'); } @@ -227,15 +228,18 @@ class ResizerTest extends TestCase public function testGeneratePdfImages(): void { Setting::set('folders', [['folder' => '/pages']]); - Setting::set('sizes', []); - Setting::set('breakpoints', []); + Setting::set('sizes', [['name' => 'testas', 'aspect_ratio' => '1x1']]); + Setting::set('breakpoints', [200]); $media = MediaLibrary::instance(); $media->put('/pages/test.pdf', file_get_contents(__DIR__.'/stub/dummy.pdf')); Event::fire('media.file.upload', [null, '/pages/test.pdf', null]); - $this->assertHasFile('pages/test-1275x1650.jpg'); - $this->assertFileCount(1, 'pages'); + $this->assertHasFile('pages/test-1275x1650.pdf.jpg'); + $this->assertHasFile('pages/test-1275x1275.pdf.jpg'); + $this->assertHasFile('pages/test-200x259.pdf.jpg'); + $this->assertHasFile('pages/test-200x200.pdf.jpg'); + $this->assertFileCount(4, 'pages'); } }