Jump to content

PHP imagecolorallocate


floppydrivez

Recommended Posts

A little tuff to explain, but this is not working on some servers.  This is the code

 

// Split the HTML color representation
$bgcolor = $_GET['bgcolor'];
$tcolor = $_GET['tcolor'];
function string_split($str, $nr){   
   return split("-l-", chunk_split($str, $nr, '-l-'));
}
$hexcolor1 = string_split($bgcolor, 2);
$hexcolor2 = string_split($tcolor, 2);

// Convert HEX values to DECIMAL
$bincolor1[0] = hexdec("0x{$hexcolor1[0]}");
$bincolor1[1] = hexdec("0x{$hexcolor1[1]}");
$bincolor1[2] = hexdec("0x{$hexcolor1[2]}");
$bincolor2[0] = hexdec("0x{$hexcolor2[0]}");
$bincolor2[1] = hexdec("0x{$hexcolor2[1]}");
$bincolor2[2] = hexdec("0x{$hexcolor2[2]}");
$font	= 2;
$width = strlen($protect_string) * ImageFontWidth($font);
$height	= ImageFontHeight($font);
$im = @imagecreate ($width,$height);
//Create background
$background_color = ImageColorAllocate($im, "$bincolor1[0]", "$bincolor1[1]", "$bincolor1[2]"); 
//Create Text
$text_color = ImageColorAllocate($im, "$bincolor2[0]", "$bincolor2[1]", "$bincolor2[2]");
imagestring ($im, $font, 0, 0,  $protect_string, $text_color);
imagejpeg ($im);
ImageDestroy($im);

 

Below are the errors

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in ../Clan_Roster/files/protect.php on line 24

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in ../Clan_Roster/files/protect.php on line 26

Warning: imagestring(): supplied argument is not a valid Image resource in ../Clan_Roster/files/protect.php on line 27

Warning: imagejpeg(): supplied argument is not a valid Image resource in ../Clan_Roster/files/protect.php on line 28

Warning: imagedestroy(): supplied argument is not a valid Image resource in ../Clan_Roster/files/protect.php on line 29

 

It works fine on some servers and not on others.  Does anyone know what might be causing this not to work on some?

Link to comment
https://forums.phpfreaks.com/topic/39193-php-imagecolorallocate/
Share on other sites

It's more likely the error reporting levels are different on the servers, and you only see the warnings on some.

You're surpressing the error that actually matters:

$im = @imagecreate ($width,$height);

 

Needs to be :

$im = imagecreate ($width,$height);

In order to get an error that will help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.