Skip to content

Commit beecc91

Browse files
committed
Improve PHP 8.5 compatibility
- only use imagedestroy with PHP < 8 - only use xml_parser_free with PHP < 8
1 parent ee5bab8 commit beecc91

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/Svg/Document.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ function ($parser, $name) {}
161161
}
162162
xml_parse($parser, "", true);
163163

164-
xml_parser_free($parser);
164+
if (PHP_MAJOR_VERSION < 8) {
165+
xml_parser_free($parser);
166+
}
165167

166168
return $this->handleSizeAttributes($rootAttributes);
167169
}
@@ -257,7 +259,9 @@ public function render(SurfaceInterface $surface)
257259

258260
xml_parse($parser, "", true);
259261

260-
xml_parser_free($parser);
262+
if (PHP_MAJOR_VERSION < 8) {
263+
xml_parser_free($parser);
264+
}
261265
}
262266

263267
protected function svgOffset($attributes)

src/Svg/Surface/CPdf.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5658,7 +5658,9 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
56585658
// Cast to 8bit+palette
56595659
$imgalpha_ = @imagecreatefrompng($tempfile_alpha);
56605660
imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
5661-
imagedestroy($imgalpha_);
5661+
if (PHP_MAJOR_VERSION < 8) {
5662+
imagedestroy($imgalpha_);
5663+
}
56625664
imagepng($imgalpha, $tempfile_alpha);
56635665
} else {
56645666
$tempfile_alpha = null;
@@ -5711,7 +5713,9 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
57115713
// extract image without alpha channel
57125714
$imgplain = imagecreatetruecolor($wpx, $hpx);
57135715
imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
5714-
imagedestroy($img);
5716+
if (PHP_MAJOR_VERSION < 8) {
5717+
imagedestroy($img);
5718+
}
57155719

57165720
imagepng($imgalpha, $tempfile_alpha);
57175721
imagepng($imgplain, $tempfile_plain);
@@ -5722,13 +5726,17 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
57225726
// embed mask image
57235727
if ($tempfile_alpha) {
57245728
$this->addImagePng($imgalpha, $tempfile_alpha, $x, $y, $w, $h, true);
5725-
imagedestroy($imgalpha);
5729+
if (PHP_MAJOR_VERSION < 8) {
5730+
imagedestroy($imgalpha);
5731+
}
57265732
$this->imageCache[] = $tempfile_alpha;
57275733
}
57285734

57295735
// embed image, masked with previously embedded mask
57305736
$this->addImagePng($imgplain, $tempfile_plain, $x, $y, $w, $h, false, ($tempfile_alpha !== null));
5731-
imagedestroy($imgplain);
5737+
if (PHP_MAJOR_VERSION < 8) {
5738+
imagedestroy($imgplain);
5739+
}
57325740
$this->imageCache[] = $tempfile_plain;
57335741
}
57345742

@@ -5813,11 +5821,13 @@ function addPngFromFile($file, $x, $y, $w = 0, $h = 0)
58135821
}
58145822

58155823
imagecopy($img, $imgtmp, 0, 0, 0, 0, $sx, $sy);
5816-
imagedestroy($imgtmp);
5824+
if (PHP_MAJOR_VERSION < 8) {
5825+
imagedestroy($imgtmp);
5826+
}
58175827
}
58185828
$this->addImagePng($img, $file, $x, $y, $w, $h);
58195829

5820-
if ($img) {
5830+
if ($img && PHP_MAJOR_VERSION < 8) {
58215831
imagedestroy($img);
58225832
}
58235833
}

0 commit comments

Comments
 (0)