Skip to content

Commit 32a2bfb

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 32a2bfb

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
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: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,7 +5612,9 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
56125612
// Cast to 8bit+palette
56135613
$imgalpha_ = @imagecreatefrompng($tempfile_alpha);
56145614
imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
5615-
imagedestroy($imgalpha_);
5615+
if (PHP_MAJOR_VERSION < 8) {
5616+
imagedestroy($imgalpha_);
5617+
}
56165618
imagepng($imgalpha, $tempfile_alpha);
56175619

56185620
// Make opaque image
@@ -5658,7 +5660,9 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
56585660
// Cast to 8bit+palette
56595661
$imgalpha_ = @imagecreatefrompng($tempfile_alpha);
56605662
imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
5661-
imagedestroy($imgalpha_);
5663+
if (PHP_MAJOR_VERSION < 8) {
5664+
imagedestroy($imgalpha_);
5665+
}
56625666
imagepng($imgalpha, $tempfile_alpha);
56635667
} else {
56645668
$tempfile_alpha = null;
@@ -5711,7 +5715,9 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
57115715
// extract image without alpha channel
57125716
$imgplain = imagecreatetruecolor($wpx, $hpx);
57135717
imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
5714-
imagedestroy($img);
5718+
if (PHP_MAJOR_VERSION < 8) {
5719+
imagedestroy($img);
5720+
}
57155721

57165722
imagepng($imgalpha, $tempfile_alpha);
57175723
imagepng($imgplain, $tempfile_plain);
@@ -5722,13 +5728,17 @@ protected function addImagePngAlpha($file, $x, $y, $w, $h, $byte)
57225728
// embed mask image
57235729
if ($tempfile_alpha) {
57245730
$this->addImagePng($imgalpha, $tempfile_alpha, $x, $y, $w, $h, true);
5725-
imagedestroy($imgalpha);
5731+
if (PHP_MAJOR_VERSION < 8) {
5732+
imagedestroy($imgalpha);
5733+
}
57265734
$this->imageCache[] = $tempfile_alpha;
57275735
}
57285736

57295737
// embed image, masked with previously embedded mask
57305738
$this->addImagePng($imgplain, $tempfile_plain, $x, $y, $w, $h, false, ($tempfile_alpha !== null));
5731-
imagedestroy($imgplain);
5739+
if (PHP_MAJOR_VERSION < 8) {
5740+
imagedestroy($imgplain);
5741+
}
57325742
$this->imageCache[] = $tempfile_plain;
57335743
}
57345744

@@ -5813,11 +5823,13 @@ function addPngFromFile($file, $x, $y, $w = 0, $h = 0)
58135823
}
58145824

58155825
imagecopy($img, $imgtmp, 0, 0, 0, 0, $sx, $sy);
5816-
imagedestroy($imgtmp);
5826+
if (PHP_MAJOR_VERSION < 8) {
5827+
imagedestroy($imgtmp);
5828+
}
58175829
}
58185830
$this->addImagePng($img, $file, $x, $y, $w, $h);
58195831

5820-
if ($img) {
5832+
if ($img && PHP_MAJOR_VERSION < 8) {
58215833
imagedestroy($img);
58225834
}
58235835
}

0 commit comments

Comments
 (0)