diff --git a/src/Pdf.php b/src/Pdf.php index 697b983..8f4dcb1 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -3,6 +3,7 @@ namespace Spatie\PdfToImage; use Imagick; +//use ImagickPixel; use Spatie\PdfToImage\Exceptions\InvalidFormat; use Spatie\PdfToImage\Exceptions\PageDoesNotExist; use Spatie\PdfToImage\Exceptions\PdfDoesNotExist; @@ -22,6 +23,10 @@ class Pdf protected $validOutputFormats = ['jpg', 'jpeg', 'png']; protected $layerMethod = Imagick::LAYERMETHOD_FLATTEN; + + protected $alphaChannel; + + protected $backgroundColor; protected $colorspace; @@ -87,6 +92,19 @@ class Pdf return $this; } + + public function setImageAlphaChannel(int $alphaChannel) + { + $this->alphaChannel = $alphaChannel; + + return $this; + } + + public function setImageBackgroundColor(/*ImagickPixel*/string $backgroundColor) { + $this->backgroundColor = $backgroundColor; + + return $this; + } public function isValidOutputFormat(string $outputFormat): bool { @@ -156,7 +174,7 @@ class Pdf if ($this->colorspace !== null) { $this->imagick->setColorspace($this->colorspace); } - + if ($this->compressionQuality !== null) { $this->imagick->setCompressionQuality($this->compressionQuality); } @@ -174,6 +192,14 @@ class Pdf if ($this->thumbnailWidth !== null) { $this->imagick->thumbnailImage($this->thumbnailWidth, 0); } + + if ($this->backgroundColor !== null) { + $this->imagick->setImageBackgroundColor($this->backgroundColor); + } + + if ($this->alphaChannel !== null) { + $this->imagick->setImageAlphaChannel($this->alphaChannel); + } $this->imagick->setFormat($this->determineOutputFormat($pathToImage));