Description: [PATCH] Fix imagedestroy() deprecation warning in PHP 8.5
 imagedestroy() has been a no-op since PHP 8.0 and is formally
 deprecated in PHP 8.5. Wrap all 6 calls with a version check
 to suppress the deprecation notice.
Author: Georgii Kolotov <skab.working@gmail.com>
Origin: vendor, https://github.com/tecnickcom/TCPDF/commit/c9a407e72ec34dc37a723b08265a7d0a5890917a
Bug: https://github.com/tecnickcom/TCPDF/issues/843
Last-Update: 2026-02-18
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/

diff --git a/include/tcpdf_images.php b/include/tcpdf_images.php
index 6f2860c6..faa35a36 100644
--- a/include/tcpdf_images.php
+++ b/include/tcpdf_images.php
@@ -126,7 +126,9 @@ public static function _toPNG($image, $tempfile) {
 		// create temporary PNG image
 		imagepng($image, $tempfile);
 		// remove image from memory
-		imagedestroy($image);
+		if (PHP_VERSION_ID < 80000) {
+			imagedestroy($image);
+		}
 		// get PNG image data
 		$retvars = self::_parsepng($tempfile);
 		// tidy up by removing temporary image
@@ -145,7 +147,9 @@ public static function _toPNG($image, $tempfile) {
 	 */
 	public static function _toJPEG($image, $quality, $tempfile) {
 		imagejpeg($image, $tempfile, $quality);
-		imagedestroy($image);
+		if (PHP_VERSION_ID < 80000) {
+			imagedestroy($image);
+		}
 		$retvars = self::_parsejpeg($tempfile);
 		// tidy up by removing temporary image
 		unlink($tempfile);
diff --git a/tcpdf.php b/tcpdf.php
index 2cbbc4d7..18367aab 100644
--- a/tcpdf.php
+++ b/tcpdf.php
@@ -7437,12 +7437,16 @@ protected function ImagePngAlpha($file, $x, $y, $wpx, $hpx, $w, $h, $type, $link
 					}
 				}
 				imagepng($imgalpha, $tempfile_alpha);
-				imagedestroy($imgalpha);
+				if (PHP_VERSION_ID < 80000) {
+					imagedestroy($imgalpha);
+				}
 				// extract image without alpha channel
 				$imgplain = imagecreatetruecolor($wpx, $hpx);
 				imagecopy($imgplain, $img, 0, 0, 0, 0, $wpx, $hpx);
 				imagepng($imgplain, $tempfile_plain);
-				imagedestroy($imgplain);
+				if (PHP_VERSION_ID < 80000) {
+					imagedestroy($imgplain);
+				}
 				$parsed = true;
 			} catch (Exception $e) {
 				// GD fails
diff --git a/tcpdf_barcodes_1d.php b/tcpdf_barcodes_1d.php
index 45d35616..cf3ebfe9 100644
--- a/tcpdf_barcodes_1d.php
+++ b/tcpdf_barcodes_1d.php
@@ -234,7 +234,9 @@ public function getBarcodePngData($w=2, $h=30, $color=array(0,0,0)) {
 			ob_start();
 			imagepng($png);
 			$imagedata = ob_get_clean();
-			imagedestroy($png);
+			if (PHP_VERSION_ID < 80000) {
+				imagedestroy($png);
+			}
 			return $imagedata;
 		}
 	}
diff --git a/tcpdf_barcodes_2d.php b/tcpdf_barcodes_2d.php
index 730361bd..410a1c22 100644
--- a/tcpdf_barcodes_2d.php
+++ b/tcpdf_barcodes_2d.php
@@ -238,7 +238,9 @@ public function getBarcodePngData($w=3, $h=3, $color=array(0,0,0)) {
 			ob_start();
 			imagepng($png);
 			$imagedata = ob_get_clean();
-			imagedestroy($png);
+			if (PHP_VERSION_ID < 80000) {
+				imagedestroy($png);
+			}
 			return $imagedata;
 		}
 	}
