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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.