I am new to PHP and my first project is that i have to migrate a website from PHP 5 to PHP 8. At the beginning it was very easy to solve some Errors but now there is thios error:
Fatal error: Uncaught TypeError: imagecolorallocatealpha(): Argument #1 ($image) must be of type GdImage, null given in C:\xampp\htdocs\Verbrauchsmaterial\daten\pchart\class\pDraw.class.php:1206 Stack trace: #0 C:\xampp\htdocs\Verbrauchsmaterial\daten\pchart\class\pDraw.class.php(1206): imagecolorallocatealpha(NULL, 170, 183, 87, 0) #1 C:\xampp\htdocs\Verbrauchsmaterial\daten\pchart\class\pDraw.class.php(504): pDraw->allocateColor(NULL, 170, 183, 87, 0) #2 C:\xampp\htdocs\Verbrauchsmaterial\administration\server\loginstat.php(53): pDraw->drawFilledRectangle(0, 0, 700, 400, Array) #3 C:\xampp\htdocs\Verbrauchsmaterial\administration\body.php(114): include_once('C:\xampp\htdocs...') #4 C:\xampp\htdocs\Verbrauchsmaterial\administration\index.php(24): include_once('C:\xampp\htdocs...') #5 {main} thrown in C:\xampp\htdocs\Verbrauchsmaterial\daten\pchart\class\pDraw.class.php on line 1206
Because i am not able to solve this Error i wanted to ask, if somebody could look over my code and maybe tell me whats wrong with it
This is my code until line 1206 (if there is an option to add the file of the code i could add it to the question):
if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
return(-1);
if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
if ( !$this->Antialias )
{
if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
{
$ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
}
$PlotColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
imagesetpixel($this->Picture,$X,$Y,$PlotColor);
return(0);
}
$Plot = "";
$Xi = floor($X);
$Yi = floor($Y);
if ( $Xi == $X && $Yi == $Y)
{
if ( $Alpha == 100 )
$this->drawAlphaPixel($X,$Y,100,$R,$G,$B);
else
$this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
}
else
{
$Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
$Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
$Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
$Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
}
}
/* Draw a semi-transparent pixel */ function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B) { if ( isset($this->Mask[$X])) { if ( isset($this->Mask[$X][$Y]) ) { return(0); } }
if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
return(-1);
if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
{
$AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
$ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$AlphaFactor);
imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
}
$C_Aliased = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
}
/* Convert apha to base 10 / function convertAlpha( $AlphaValue) { return((127/100)(100-$AlphaValue)); }
/* Allocate a color with transparency */
function allocateColor( $Picture,$R,$G,$B,$Alpha=100)
{
if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
if ( $Alpha < 0 ) { $Alpha = 0; }
if ( $Alpha > 100) { $Alpha = 100; }
$Alpha = $this->convertAlpha($Alpha);
return(imagecolorallocatealpha($Picture,$R,$G,$B,$Alpha));
}
` The last line is line 1206