PDA

View Full Version : Stupid image functions...



Jubba
June 27th, 2003, 12:47 AM
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?

ahmed
June 27th, 2003, 12:58 AM
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 :)

Jubba
June 27th, 2003, 01:12 AM
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 :)

ahmed
June 27th, 2003, 01:18 AM
lol.. im very interested in seeing the results :beam:

Jubba
June 27th, 2003, 01:20 AM
here is what I have so far!

http://www.bluefinatlantic.com/egTest/imageFunc/random/random2.php

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. :) But if you are interested then I might as well show you now ;)

ahmed
June 27th, 2003, 01:24 AM
Originally posted by Jubba
here is what I have so far!

http://www.bluefinatlantic.com/egTest/imageFunc/random/random2.php that's awesome really.. im impressed =)

Jubba
June 27th, 2003, 01:25 AM
I'm excited. This will end up being my footer but completely code generated and entirely random. :)

Jubba
June 27th, 2003, 01:32 AM
lol, now it should show up as random bgcolors...

ahmed
June 27th, 2003, 01:37 AM
awesome!

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

BobbyDouglas
June 27th, 2003, 11:24 PM
Originally posted by Jubba
lol, now it should show up as random bgcolors...

You gunna share the code? :chinaman:

Jubba
June 27th, 2003, 11:28 PM
no :P

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

BobbyDouglas
September 30th, 2003, 04:07 PM
2 months later... You gunna share the code?

DigitalPimp
September 30th, 2003, 04:19 PM
What is the point of this script?? I don't really understand the reasoning behind it. Why not just make a image with a clear BG and then put a span around it and do a random on the span BG color?

Jubba
September 30th, 2003, 06:37 PM
It was just getting into the image functions of PHP. I honestly haven't modified the code since I posted this... if I find it I'll try to clean it up, but the code would be pretty much the ssame...