spipu / html2pdf

OFFICIAL PROJECT | HTML to PDF converter written in PHP
http://html2pdf.fr/en/default
Open Software License 3.0
1.67k stars 748 forks source link

Webp transparency not managed - La transparence des Webp n'est pas gérée #767

Open Tonygolf opened 1 year ago

Tonygolf commented 1 year ago

Hello, I'm using the spipu html2pdf and I have a problem with webp images, transparency is replace by black color. Does anyone have a solution ? Thanks, Antoine

Bonjour, J'utilise html2pdf par spipu et j'ai un problème avec les images webp, le fond transparent est remplacé par du noir. Quelqu'un a-t-il une solution ? Merci, Antoine

PS: J'ai vu que le gérant est français alors j'en profite, merci pour le boulot.

Tonygolf commented 1 year ago

I've made something to solve this, that's not very pretty but that's work... I create png from the webp, I add this at line 1519 in Html2Pdf.php :

// Webp to Png if(exif_imagetype($src)===18){ $image_origine=imagecreatefromwebp($src); $w = imagesx($image_origine); $h = imagesy($image_origine);

// create a canvas

            $im = imagecreatetruecolor ($w, $h);
            imageAlphaBlending($im, false);
            imageSaveAlpha($im, true);

// By default, the canvas is black, so make it transparent

            $trans = imagecolorallocatealpha($im, 0, 0, 0, 127);
            imagefilledrectangle($im, 0, 0, $w - 1, $h - 1, $trans);

// copy png to canvas imagecopy($im, $image_origine, 0, 0, 0, 0, $w, $h);

            $nom = 'temp_'.time().rand().'.png';
            $chemin = '/temp';
            $adresse = $chemin.'/'.$nom;

            imagepng($im, $adresse, -1,-1);
            imagedestroy($im);
            $src=$adresse;
        }