Jump to content

[SOLVED] ImageColorAllocate()


JBS103

Recommended Posts

I've created a function to allocate colors with Hexadecimal codes. Right now, it isn't creating any errors, its only outputting black.

<?php
header ("Content-type: image/png");

function getColor($colorValue, &$img_handle)
{

$colorValue = trim($colorValue, "#");
$colorValue = str_split($colorValue, 2);
for($x = 0; $x < 3; $x++) { $colorValue[$x] = "0x".$colorValue[$x]; }

return ImageColorAllocate($img_handle, $colorValue[0], $colorValue[1], $colorValue[2]);
}

$img_handle = ImageCreate (20, 20);
$color = getColor("#FFFFFF", $img_handle);
imagefill($img_handle, 0, 0, $color);
ImagePng ($img_handle); 
?>

 

Is there a better way to do this all together? The function seems to output correctly.

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

Nevermind. I settled for this if anyone is interested.

<?php
header ("Content-type: image/png");
function getColor($colorValue, &$img_handle)
{
$colorValue = trim($colorValue, "#");
$colorValue = str_split($colorValue, 2);
return ImageColorAllocate($img_handle, hexdec($colorValue[0]), hexdec($colorValue[1]), hexdec($colorValue[2]));
}
$img_handle = ImageCreate (20, 20);
$color = getColor("#FFFFFF", $img_handle);
imagefill($img_handle, 0, 0, $color);
ImagePng ($img_handle); 
?>

 

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.