I'm trying to create a page which asks for 5 alphanumeric numbers
It then creates an image out of the input (if its valid)
php_class.teamluke.net/Assignment_8/index.php (attachment)
As of now, I get an image, the background, lines, and pixels all over the place
I'm trying to figure out how to add each character (which is to be rotated 10 degrees from the last character) to that image.
My best guess is to create an image out of each character, rotate it, then add it to the other image.
Heres what I have so far...
function displayImage($input) {
//create a blank image (width & height) and assign it to a variable
$my_img = imagecreate( 200, 50 );
//get the background ready (using RGB values)
$background = imagecolorallocate( $my_img, 255, 230, 230 );
//get the text color ready (using RGB values)
$text_color = imagecolorallocate( $my_img, 102, 0, 0 );
//line (also using RGB)
$line_color = imagecolorallocate( $my_img, 0, 0, 0 );
//fill the image with background
imagefill( $my_img, 0, 0, $background);
imagesetthickness ( $my_img, 5 );
//create a border (start_x, start_y,end_x,end_y)
imageline($my_img, 0, 0, 0, 50, $line_color);
imageline($my_img, 200, 0, 200, 50, $line_color);
imageline($my_img, 0, 0, 200, 0, $line_color);
imageline($my_img, 0, 50, 200,50, $line_color);
//add random lines
$line_color = imagecolorallocate( $my_img, 204, 0, 0 );
imagesetthickness ( $my_img, 2 );
imageline($my_img, rand(0,200), rand(0,50), rand(0,200), rand(0,50), $line_color);
imageline($my_img, rand(0,200), rand(0,50), rand(0,200), rand(0,50), $line_color);
imageline($my_img, rand(0,200), rand(0,50), rand(0,200), rand(0,50), $line_color);
imageline($my_img, rand(0,200), rand(0,50), rand(0,200), rand(0,50), $line_color);
imageline($my_img, rand(0,200), rand(0,50), rand(0,200), rand(0,50), $line_color);
//add a few pixels
$line_color = imagecolorallocate( $my_img, 0, 0, 0 );
for($i=0;$i<=1000;$i++) {
imagesetpixel($my_img, rand(0,200),rand(0,50), $line_color);
}
// # of characters
$l = strlen($input);
//do stuff to each char
for ( $i = 0; $i < $l; $i++ ) {
$char = substr( $input, $i, 1 );
//char contains the current character so make $char an image
$char_img = imagecreate(10,50);
//fill the image with background
imagefill( $char_img, 0, 0, $background);
imagestring($char_img, 5, 0, 20, $char, $text_color);
//wouldn't this rotate $char_img by 10 degrees and set its background to the main images
imagerotate($char_img, ($i * 10), $background);
//copy new image to main image
//imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
imagecopy( $my_img, $char_img, 20, 50, 0, 0, 10, 50);
}
//place user input on the dynamic image (font size,x,y,text,font color)
// display image, or add second parameter to save it (imagepng($my_img,"Dynamic_image.png")
imagepng( $my_img );
//free resources just to be sure
imagecolordeallocate( $my_img, $text_color );
imagecolordeallocate( $my_img, $background );
imagedestroy( $my_img );
}
any ideas?