spatie / pdf-to-image

Convert a pdf to an image
https://murze.be/2015/07/convert-a-pdf-to-an-image-using-php/
MIT License
1.32k stars 228 forks source link

Image has a black background color #196

Closed dev-panpic closed 1 year ago

dev-panpic commented 2 years ago

I converted from a pdf file to an image, but the image has a black background color How do I fixed?

liudding commented 2 years ago

I found a way to fix it.

public function getImageData($pathToImage)
    {
        $imagick = new \Imagick();

        $imagick->setResolution($this->resolution, $this->resolution);

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

        // Remove alpha channel here
        $imagick->setImageBackgroundColor(new \ImagickPixel('WHITE'));
        $imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);

        $imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);

        $imagick->setFormat($this->determineOutputFormat($pathToImage));

        return $imagick;
    }
cbrody commented 2 years ago

This doesn't fix it for me unfortunately:

20936IIED pdf-p1

Source pdf: 20936IIED.pdf

cbrody commented 2 years ago

This patch fixes the issue: https://www.drupal.org/files/issues/2021-12-03/remote-pdf-overlap-3221786-8.patch

spatie-bot commented 1 year ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.