-
- header("content-type:image/jpeg");
- /*1. Simple image output*/
- $im = imagecreate(60,40);
- $pink = imagecolorallocate($im,35, 25,220);
- imagejpeg($im);
- //imagestring($im,16, 200, 200,"I LOVE YOU",);
- /* 2. Write the string Into the image*/
- //Load the image
- $me=imagecreatefromjpeg("../../images/3.jpg");
- //Set the font color
- $text_color = imagecolorallocate($me, 255, 84,0);
- //The position of the set font
- $font = "C:WindowsFontssimkai.ttf";
- //The string to be written
- $str = iconv('GBK',"UTF-8", "php development...");
- //Write the string into the image
- imagettftext($me,20,0,50,50, $text_color,$font, $str);
- //Output the image
- imagejpeg($me);
- //Release resources
- imagedestroy($me);
Copy code
- session_start();
- header("content-type:image/jpeg");
- //Verification code
- //Image width
- $image_width =65;
- //Image height
- $image_height =45;
- //Set the random number seed
- //srand(microtime()*1000);
- for ($i=0;$i<6;$i++){
- $new_str .=dechex(rand(0, 100 ));
- }
- $_SESSION[code]=$new_str;
- $image = imagecreate($image_width, $image_height);
- imagecolorallocate($image,rand(0,255), rand(0,255),rand(0,255)) ;
- for ($i=0;$i
- $font = mt_rand(3, 8);//Generate random font size
- $x = mt_rand(3 ,10)+$image_width*$i/4;
- $y = mt_rand(3,$image_height/4);
- $color = imagecolorallocate($image,mt_rand(0, 255), mt_rand(0, 255), mt_rand (0, 255));
- imagestring($image, $font, $x, $y,$_SESSION[code][$i], $color);
- }
- imagepng($image);
- imagedestroy($image );
Copy code
|