From 2d6e124ee3067360c78919e8840c647d62b30b94 Mon Sep 17 00:00:00 2001 From: michael-e Date: Thu, 28 Feb 2019 16:35:22 +0100 Subject: [PATCH] Prevent warning for index larger than pallet size PHP throws a "Warning: imagecolorsforindex(): Color index ... out of range in..." if the index returned by imagecolortransparent() is larger than the pallet size of the image in question. See https://stackoverflow.com/a/3898007 Fixes #165 --- lib/class.imagefilter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/class.imagefilter.php b/lib/class.imagefilter.php index c773899..533eca6 100755 --- a/lib/class.imagefilter.php +++ b/lib/class.imagefilter.php @@ -18,7 +18,8 @@ protected static function __fill(&$res, &$dst, $colour = null){ if(!$colour || strlen(trim($colour)) == 0){ $tr_idx = imagecolortransparent($res); - if($tr_idx >= 0){ + $palletsize = imagecolorstotal($res); + if($tr_idx >= 0 && $tr_idx < $palletsize){ $tr_colour = imagecolorsforindex($res, $tr_idx); $tr_idx = imagecolorallocate($dst, $tr_colour['red'], $tr_colour['green'], $tr_colour['blue']); imagefill($dst, 0, 0, $tr_idx);