Jump to content

GD making colours dark


idire

Recommended Posts

I'm creating images using GD by:

 

making a canvas, adding a background, adding some text then adding more images on top:

 

This works fine, but the images added come out a lot darker than they should with certain background colours.

 

Any way to resolve this? something wrong with my code?

 

proper colours:

signatureko0.gif

 

bad colours:

signature43eg8.gif

 

<?php

$image = $_POST['picture'];
$colour = $_POST['selectcolour'];

$imColor = hex2int(validHexColor($colour));
$imText = hex2int(validHexColor($var2));

$insert = imagecreatefromgif($image);
imagecolortransparent($insert,imagecolorat($insert,0,0));

$insert_x = imagesx($insert); 
$insert_y = imagesy($insert);

$yvar = 140;
//$yvar = $insert_y + '10';
//if($yvar > 150) { $yvar = 150; }
$xpos = '315' - $insert_x;

//create the image
$im = imageCreate(320,$yvar);
$font = imageloadfont('chowfun.gdf');

//assign colours from hex values
$background = imageColorAllocate($im, $imColor['r'], $imColor['g'], $imColor['b']);
$textcolor = imageColorAllocate($im, $imText['r'], $imText['g'], $imText['b']);

//add text to the signature
imagestring($im, 3, 220, 0, "RSTRACKING.COM", $textcolor);
imagestring($im, $font, 2, 2, "Idire_2005", $textcolor);

//add the second image to the base image
imagecopymerge($im,$insert,$xpos,5,0,0,$insert_x,$insert_y,100);

//retrieve stats from highscores
$username = 'Idire_2005';
$temp = str_replace(" ", "_", $username);
$file = file_get_contents ('http://hiscore.runescape.com/index_lite.ws?player='.$temp.'');
$file = ereg_replace("\n", " ", $file);

$a = explode(' ',$file); 
foreach ($a as $b) { 
   		$c[] = explode(',',$b);
}

$skills	= array('attack','defence','strength','hitpoint','ranged','prayer','magic','cooking','woodcutting','fletching','fishing','firemaking','crafting','smithing','mining','herblore','agility','thieving','slayer','farming','runecraft','hunter','construction','summoning');
$i = 0;
$xpos = 10;
$ypos = 30;
while($i < 24) {

	$url = 'signatures/skillico/'.$skills[$i].'.gif';
	$icon = imagecreatefromgif($url);
	//imagecolortransparent($icon,imagecolorat($im,0,0));
	$icon_x = imagesx($icon); 
	$icon_y = imagesy($icon);
	imagecopymerge($im,$icon,$xpos,$ypos,0,0,$icon_x,$icon_y,100);
	imagestring($im, 3, ($xpos + 26), ($ypos + 5), $c[($i +1)][1], $textcolor);
	$xpos = $xpos + 42;
	if($i == 5 || $i == 11 || $i == 17) { $ypos = $ypos + 27; $xpos = 10; }
	$i++;
}

//define type of output image
//header('Content-type: image/gif');

//output and destroy the image from memory
//imageGIF($im);
imageGIF($im,'signatures/signature.gif');
imageDestroy($im);


?>

 

Creation script: http://www.rstracking.com/test.php

Link to comment
https://forums.phpfreaks.com/topic/116737-gd-making-colours-dark/
Share on other sites

Colour functions

 

<?php

function hex2int($hex) {
return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
			  'g' => hexdec(substr($hex, 2, 2)), // 2nd pair
			  'b' => hexdec(substr($hex, 4, 2))  // 3rd pair
			);
}
function validHexColor($input = '000000', $default = '000000') {
// A valid Hexadecimal color is exactly 6 characters long
// and eigher a digit or letter from a to f
return (eregi('^[0-9a-f]{6}$', $input)) ? $input : $default ;
} 

?>

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.