|
//************************************** **//
// 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.
}
?> |