Fanwe's image plug-in can be used for forums and blogs to present user information and some latest news in the form of images.
If you need to develop this function on your own, you need to set images in a certain format (or address) to use scripts for processing.
In Perl
For example, you can use the locationmatch or filesmatch command of Apache to set up a Perl module for processing.
If you use Mason, it is simpler. You do not need to modify the server. You only need to use the dhandler feature to let the specified script handle it.
The basic process is as follows:
The main code is as follows:
My $ uri = $ R-> URI; </P> <p> if ($ uri = ~ /. JPG $/) {<br/> $ uid = substr ($ uid, 1,-4 ); # obtain uid from URI </P> <p> my $ image_template_path = $ M-> callers (0)-> source_dir. '/images/'; # background image folder <br/> my $ username = User: GetUserName ($ UID); </P> <p> $ counter = imagecreate :: create ($ total, $ username, $ image_template_path); # create an image <br/> $ R-> content_type ('image/jpg '); <br/> $ R-> headers_out; <br/> Print $ counter; <br/>}
PHP is similar. For example, you can set it in Apache or in the. htaccess file:
<Directory/var/www/php.hfahe.cn> <br/> redirectmatch ^/(. *)/. jpg $/avatar. php? Type = $1 <br/> </directory>
The PHP code is as follows:
Include ('lib/Conn. PHP '); </P> <p> // obtain the user ID from the parameter <br/> $ input_param = $ _ Get ["type"]; <br/> preg_match_all ("| r (. *) _ | u ", $ input_param, $ preg_out ); </P> <p> // obtain the user nickname from the database <br/> $ SQL _string = "select username from user where id = ". $ preg_out [1] [0]; </P> <p> $ result = mysql_db_query ($ mysql_database, $ SQL _string, $ conn ); </P> <p> $ ROW = mysql_fetch_row ($ result); </P> <p> $ user_nickname = $ row [0]; </P> <p> header ("Content-Type: image/JPEG "); </P> <p> // create an image with a width of 119 and a height of 126 pixels <br/> $ background_image = imagecreatetruecolor (119,126 ); </P> <p> // obtain the text color, RGB <br/> $ background_color = imagecolorallocate ($ background_image, 250,228,130 ); </P> <p> // read our background image <br/> $ source_image = imagecreatefrompng ('images/u0_2.png '); </P> <p> // copy the background image to the image to be output. <br/> imagecopy ($ background_image, $ source_image, 0, 0, 0, 0,119,126); </P> <p> // use a font that supports Chinese characters <br/> $ text_font = '/usr/share/fonts/Vista/msyh. ttf'; <br/> $ text_size = 10; </P> <p> // write the user nickname to the image. <br/> imagettftext ($ background_image, $ text_size, 0, 8, 40, $ background_color, $ text_font, $ user_nickname); </P> <p> // output PNG image content <br/> imagejpeg ($ background_image ); </P> <p> // disable the previously used image buffer <br/> imagedestroy ($ background_image); <br/> imagedestroy ($ simage );
Then, we can see the image we need when calling r23_0.jpg.