Skip to content

Commit

Permalink
remove initialization of imagick instance from constructor as it is u…
Browse files Browse the repository at this point in the history
…nneeded
  • Loading branch information
patinthehat committed May 28, 2024
1 parent 9f4114f commit 23915e7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Pdf
{
protected string $pdfFile;
protected string $filename;

protected int $resolution = 144;

Expand All @@ -36,17 +36,13 @@ class Pdf

private ?int $numberOfPages = null;

public function __construct(string $pdfFile)
public function __construct(string $filename)
{
if (! file_exists($pdfFile)) {
throw PdfDoesNotExist::for($pdfFile);
if (! file_exists($filename)) {
throw PdfDoesNotExist::for($filename);
}

$this->pdfFile = $pdfFile;

$this->imagick = new Imagick();

$this->imagick->readImage($this->pdfFile);
$this->filename = $filename;
}

public function resolution(int $dpiResolution): static
Expand Down Expand Up @@ -126,6 +122,11 @@ public function selectPages(int ...$pages): static

public function pageCount(): int
{
if ($this->imagick === null) {
$this->imagick = new Imagick();
$this->imagick->readImage($this->filename);
}

if ($this->numberOfPages === null) {
$this->numberOfPages = $this->imagick->getNumberImages();
}
Expand Down Expand Up @@ -195,7 +196,7 @@ public function getImageData(string $pathToImage, int $pageNumber): Imagick
$this->imagick->setCompressionQuality($this->compressionQuality);
}

$this->imagick->readImage(sprintf('%s[%s]', $this->pdfFile, $pageNumber - 1));
$this->imagick->readImage(sprintf('%s[%s]', $this->filename, $pageNumber - 1));

if ($this->layerMethod !== LayerMethod::None) {
$this->imagick = $this->imagick->mergeImageLayers($this->layerMethod->value);
Expand Down

0 comments on commit 23915e7

Please sign in to comment.