From 13e07c5baac96d0a234975d79c2082c75b3c47ce Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 5 Dec 2022 05:03:22 -0500 Subject: [PATCH 1/6] allow pest plugin --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index d52489a..9bc04df 100644 --- a/composer.json +++ b/composer.json @@ -37,5 +37,11 @@ }, "scripts": { "test": "vendor/bin/pest" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } } } From f2159f0f5ff9a8210dd37342c30d8a162c67e6c8 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 5 Dec 2022 05:13:09 -0500 Subject: [PATCH 2/6] remove use of pingImage, lazy load number of pages --- src/Pdf.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index b990eb3..6d86a09 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -39,12 +39,6 @@ public function __construct(string $pdfFile) } $this->pdfFile = $pdfFile; - - $this->imagick = new Imagick(); - - $this->imagick->pingImage($pdfFile); - - $this->numberOfPages = $this->imagick->getNumberImages(); } public function setResolution(int $resolution) @@ -109,6 +103,10 @@ public function setPage(int $page) public function getNumberOfPages(): int { + if ($this->numberOfPages === null) { + $this->numberOfPages = $this->imagick->getNumberImages(); + } + return $this->numberOfPages; } From 78b425427908d9261474dbd3bf09bfeafef1b2a0 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 5 Dec 2022 05:26:11 -0500 Subject: [PATCH 3/6] load pdf after creating Imagick instance --- src/Pdf.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index 6d86a09..c16ac8d 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -39,6 +39,12 @@ public function __construct(string $pdfFile) } $this->pdfFile = $pdfFile; + + $this->imagick = new Imagick(); + + $this->imagick->readImage($this->pdfFile); + + $this->numberOfPages = $this->imagick->getNumberImages(); } public function setResolution(int $resolution) @@ -100,13 +106,9 @@ public function setPage(int $page) return $this; } - + public function getNumberOfPages(): int { - if ($this->numberOfPages === null) { - $this->numberOfPages = $this->imagick->getNumberImages(); - } - return $this->numberOfPages; } From 68d266d94fbf29f4d2c04476366f30f30172cb89 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 5 Dec 2022 05:26:28 -0500 Subject: [PATCH 4/6] load pdf after creating Imagick instance --- src/Pdf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pdf.php b/src/Pdf.php index c16ac8d..22731d9 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -106,7 +106,7 @@ public function setPage(int $page) return $this; } - + public function getNumberOfPages(): int { return $this->numberOfPages; From 4604af4426c1d404400500c82102af9d5fcf5d35 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 5 Dec 2022 05:31:11 -0500 Subject: [PATCH 5/6] update ghostscript to latest version --- .github/workflows/run-tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 969d7b8..46a5ceb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,6 +15,11 @@ jobs: name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: + - name: Upgrade ghostscript + run: | + sudo apt-get update + sudo apt-get install ghostscript + - name: Checkout code uses: actions/checkout@v3 From c4413d20504eaec92d5fc76a70900867903d9047 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 5 Dec 2022 05:35:28 -0500 Subject: [PATCH 6/6] lazy-load the number of pages in the pdf --- src/Pdf.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index 22731d9..2bf06d0 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -43,8 +43,6 @@ public function __construct(string $pdfFile) $this->imagick = new Imagick(); $this->imagick->readImage($this->pdfFile); - - $this->numberOfPages = $this->imagick->getNumberImages(); } public function setResolution(int $resolution) @@ -109,6 +107,10 @@ public function setPage(int $page) public function getNumberOfPages(): int { + if ($this->numberOfPages === null) { + $this->numberOfPages = $this->imagick->getNumberImages(); + } + return $this->numberOfPages; }