Ec (2); & lt ;? Php *************************************** * function: add a text parameter to the image: $ img image file name $ new_img save another image file name, if it is null, it means no other image $ text string content text_size string size text_angle font string output angle tex script ec (2); script
//************************************** **//
// Function: add text to the image
// Parameter: $ img Image File Name
// $ New_img saves another image file name. If it is null, it means no other image is saved.
// $ Text string content
// Text_size string size
// Text_angle font string output Angle
// Output x coordinate of text_x string
// Output y coordinate from text_y string
// $ Text_font-shaped file name
// $ R, $ g, $ B string color RGB Value
//************************************** **//
Function img_text ($ img, $ new_img, $ text, $ text_size, $ text_angle, $ text_x, $ text_y, $ text_font, $ r, $ g, $ B ){
$ Text = iconv ("gb2312", "UTF-8", $ text );
Header ("Content-type: image/gif ");
$ Im = @ imagecreatefromstring (file_get_contents ($ img) or die ("opening the image failed! ");
$ Color = ImageColorAllocate ($ im, $ r, $ g, $ B );
// ImageTTFText (int im, int size, int angle, int x, int y, int col, string fontfile, string text ):
// This function writes TTF (TrueType Fonts) text to an image.
// Parameter: The size is the font size;
// Angle is the font angle, which is calculated clockwise. 0 degrees is horizontal (from left to right), and 90 degrees is the bottom-to-top text;
// The x and y parameters are the coordinate values of the text (the origin is the upper left corner );
// Col indicates the color of the word;
// Fontfile is the font file name;
// Text is the string content.
ImageTTFText ($ im, $ text_size, $ text_angle, $ text_x, $ text_y, $ color, $ text_font, $ text );
If ($ new_img = ""):
ImageGif ($ im); // do not save the image, only show
Else:
ImageGif ($ im, $ new_img); // Save the image but it is not displayed
Endif;
ImageDestroy ($ im); // ends the image and releases the memory space.
}
?>