can you have a associative array containing text in the first element and a image in the 2nd. How would you declare a array like that?
I have a function that I would like to generate a random piece of text. Then it turns the text into a image. I want to include both the text and Image in the return value (which i figured a array will work great).
below a random text string of 6 chars is turend into a image and sent back via header. but I would like to send in back in a 2 element associative array. Elm1 => random text Elm2 => generated image
so its not a image file, but a generated image.
Sorry but Im very new to PHP
//Get each letter in one variable, we will format all letters different
$letter1=substr($rand_str,0,1);
$letter2=substr($rand_str,1,1);
$letter3=substr($rand_str,2,1);
$letter4=substr($rand_str,3,1);
$letter5=substr($rand_str,4,1);
$letter6=substr($rand_str,5,1);
//Creates an image from a png file. If you want to use gif or jpg images, just use the coresponding functions: imagecreatefromjpeg and imagecreatefromgif.
$image=imagecreatefrompng("./noise.png");
//$image = imagecreate(160, 45);
//Get a random angle for each letter to be rotated with.
$angle1 = rand(-20, 20);
$angle2 = rand(-20, 20);
$angle3 = rand(-20, 20);
$angle4 = rand(-20, 20);
$angle5 = rand(-20, 20);
$angle6 = rand(-20, 20);
//Get a random font. (In this examples, the fonts are located in "fonts" directory and named from 1.ttf to 10.ttf)
$font1 = rand(1, 12).".ttf";
$font2 = rand(1, 12).".ttf";
$font3 = rand(1, 12).".ttf";
$font4 = rand(1, 12).".ttf";
$font5 = rand(1, 12).".ttf";
$font6 = rand(1, 12).".ttf";
$colors[0]=array(0,0,0);
$colors[1]=array(0,0,0);
$colors[2]=array(0,0,0);
$colors[3]=array(0,0,0);
$colors[4]=array(0,0,0);
$colors[5]=array(0,0,0);
$colors[6]=array(0,0,0);
//Get a random color for each letter.
$color1=rand(0, 6);
$color2=rand(0, 6);
$color3=rand(0, 6);
$color4=rand(0, 6);
$color5=rand(0, 6);
$color6=rand(0, 6);
//Allocate colors for letters.
$bgColor = imagecolorallocate ($image, 255, 255, 255);
$textColor1 = imagecolorallocate ($image, $colors[$color1][0],$colors[$color1][1], $colors[$color1][2]);
$textColor2 = imagecolorallocate ($image, $colors[$color2][0],$colors[$color2][1], $colors[$color2][2]);
$textColor3 = imagecolorallocate ($image, $colors[$color3][0],$colors[$color3][1], $colors[$color3][2]);
$textColor4 = imagecolorallocate ($image, $colors[$color4][0],$colors[$color4][1], $colors[$color4][2]);
$textColor5 = imagecolorallocate ($image, $colors[$color5][0],$colors[$color5][1], $colors[$color5][2]);
$textColor6 = imagecolorallocate ($image, $colors[$color6][0],$colors[$color6][1], $colors[$color6][2]);
//Write text to the image using TrueType fonts.
$size = 15;
imagestring ( $image , rand(5,8) , rand(5,15) , rand(0,17) , $letter1 , $textColor1 );
imagestring ( $image , rand(5,8) , rand(30,40) , rand(0,17) , $letter2 , $textColor2 );
imagestring ( $image , rand(5,8) , rand(55,65) , rand(0,17) , $letter3 , $textColor3 );
imagestring ( $image , rand(5,8) , rand(80,90) , rand(0,17) , $letter4 , $textColor4 );
imagestring ( $image , rand(5,8) , rand(105,115) , rand(0,17) , $letter5 , $textColor5 );
imagestring ( $image , rand(5,8) , rand(130,140) , rand(0,17) , $letter6 , $textColor6 );
header('Content-type: image/jpeg');
//Output image to browser
imagejpeg($image);
//Destroys the image
imagedestroy($image);
Im not sure why I get marked down on this.
Is this not what stackoverflow is for
( [after some effort by one self] ask a question to get a answer from someone higher skilled.)
Then you get some guy with who thinks in his oppinion that this is a silly questions and 'click' marked down. Come on admin (markdown reason).