Stupid image functions

Might as well post this question here as well… someone may learn something… I’m have a bit of trouble with the PHP image functions. The code is running correctly, but it doesnt’ show up as clearly as I would like it to…I’m trying to draw a J on the image. Here is the code:

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

$j_zero = array("1", "1", "1", "1", "1", "1", "1", "1", "1", "1");
$j_one = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_two = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_three = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_four = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_five = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_six = array("1", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_seven = array("1", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_eight = array("1", "0", "0", "0", "0", "0", "0", "0", "0", "1");
$j_nine = array("0", "1", "1", "1", "1", "1", "1", "1", "1", "0");
$letterJ = array($j_zero, $j_one, $j_two, $j_three, $j_four, $j_five, $j_six, $j_seven, $j_eight, $j_nine);


$im = ImageCreate(100, 20);

ImageColorAllocate($im, 255,0,0);

$x_start = 20;
$y_start = 5;

for($i=0;$i<sizeof($letterJ);$i++)
{
	for($j=0;$j<sizeof($letterJ[0]);$j++)
	{
		if($letterJ[$i][$j] == 1)
		{
			ImageSetPixel($im, $x_start+$j, $y_start+$i, 255255255);
		}
	}
}




ImageJPEG($im);
ImageDestroy($im);
?>

but this is what it gets me: http://www.bluefinatlantic.com/egTest/imageFunc/random/random2.php

and thats not exactly clear now is it?

if you printscreen it and zoom-in in paintbrush, you’ll see that the lines that it’s drawing are 1px wide each… if you make them wider (double the 1’s in the array) it should be much clearer :slight_smile:

actually I figured out the problem. It was becuase I was outputting as a jpg. A png, or a gif would be much clearer:) Now I just have to get my stupid function to work and I’ll be all set :slight_smile:

lol… im very interested in seeing the results :beam:

here is what I have so far!

the code is here (but its messy):

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

$im = ImageCreate(100, 20);
ImageColorAllocate($im, 255,0,0);

# Creates the "J"
$j_zero = array("0", "0", "1", "1", "1", "1", "1", "1", "1", "1");
$j_one = array("0", "0", "1", "1", "1", "1", "1", "1", "1", "1");
$j_two = array("0", "0", "0", "0", "0", "0", "0", "0", "1", "1");
$j_three = array("0", "0", "0", "0", "0", "0", "0", "0", "1", "1");
$j_four = array("0", "0", "0", "0", "0", "0", "0", "0", "1", "1");
$j_five = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$j_six = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$j_seven = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$j_eight = array("0", "0", "1", "1", "1", "1", "1", "1", "0", "0");
$j_nine = array("0", "0", "1", "1", "1", "1", "1", "1", "0", "0");
$letterJ = array($j_zero, $j_one, $j_two, $j_three, $j_four, $j_five, $j_six, $j_seven, $j_eight, $j_nine);

# Creates the "U"
$u_zero = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_one = array("1", "1", "0", "00", "0", "0", "0", "0", "1", "1");
$u_two = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_three = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_four = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_five = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_six = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_seven = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$u_eight = array("0", "0", "1", "1", "1", "1", "1", "1", "0", "0");
$u_nine = array("0", "0", "1", "1", "1", "1", "1", "1", "0", "0");
$letterU = array($u_zero, $u_one, $u_two, $u_three, $u_four, $u_five, $u_six, $u_seven, $u_eight, $u_nine);

# Creates the "B"
$b_zero = array("1", "1", "1", "1", "1", "1", "1", "1", "0", "0");
$b_one = array("1", "1", "1", "1", "1", "1", "1", "1", "0", "0");
$b_two = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$b_three = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$b_four = array("1", "1", "1", "1", "1", "1", "1", "1", "0", "0");
$b_five = array("1", "1", "1", "1", "1", "1", "1", "1", "0", "0");
$b_six = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$b_seven = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$b_eight = array("1", "1", "1", "1", "1", "1", "1", "1", "0", "0");
$b_nine = array("1", "1", "1", "1", "1", "1", "1", "1", "0", "0");
$letterB = array($b_zero, $b_one, $b_two, $b_three, $b_four, $b_five, $b_six, $b_seven, $b_eight, $b_nine);

# Creates the "A"
$a_zero = array("0", "0", "1", "1", "1", "1", "1", "1", "0", "0");
$a_one = array("0", "0", "1", "1", "1", "1", "1", "1", "0", "0");
$a_two = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$a_three = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$a_four = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$a_five = array("1", "1", "1", "1", "1", "1", "1", "0", "1", "1");
$a_six = array("1", "1", "1", "1", "1", "1", "0", "0", "1", "1");
$a_seven = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$a_eight = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$a_nine = array("1", "1", "0", "0", "0", "0", "0", "0", "1", "1");
$letterA = array($a_zero, $a_one, $a_two, $a_three, $a_four, $a_five, $a_six, $a_seven, $a_eight, $a_nine);

$color = 255255255;
$x_start = 20;
$y_start = 5;
# Function to display pixels in letters
function drawLetter($b, $image, $x, $y, $color)
{
	for($i=0;$i<sizeof($b);$i++)
	{
		for($j=0;$j<sizeof($b[0]);$j++)
		{
			if($b[$i][$j] == 1)
			{
				ImageSetPixel($image, $x + $j, $y + $i, $color);
			}
		}
	}
	$x_start = $x_start + 15;
}
drawLetter($letterJ, $im, $x_start, $y_start, $color);
$x_start = $x_start + 15;
drawLetter($letterU, $im, $x_start, $y_start, $color);
$x_start = $x_start + 15;
drawLetter($letterB, $im, $x_start, $y_start, $color);
$x_start = $x_start + 15;
drawLetter($letterB, $im, $x_start, $y_start, $color);
$x_start = $x_start + 15;
drawLetter($letterA, $im, $x_start, $y_start, $color);
$x_start = $x_start + 15;

ImagePNG($im);
ImageDestroy($im);
?>

Once I have more time to work on it, I will make the code better, shorter, and more efficient. :slight_smile: But if you are interested then I might as well show you now :wink:

*Originally posted by Jubba *
**here is what I have so far!

**
that’s awesome really… im impressed =)

I’m excited. This will end up being my footer but completely code generated and entirely random. :slight_smile:

lol, now it should show up as random bgcolors…

awesome!

when i grow up, i wanna be just like you! :stuck_out_tongue:

*Originally posted by Jubba *
**lol, now it should show up as random bgcolors… **

You gunna share the code? :chinaman:

no :stuck_out_tongue:

yeah once I fix it up a bit. I started working on something else as well (can’t stay focused for too long on one thing…)