Home >Backend Development >PHP Tutorial >PHP method to add strokes and mosaics to pictures, _PHP tutorial
The example in this article describes the method of adding strokes and mosaics to pictures in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
Mosaic: void imagemask (resource image, int x1, int y1, int x2, int y2, int deep)
imagemask() adds mosaic to the rectangular area with coordinates x1, y1 to x2, y2 (the upper left corner of the image is 0, 0).
deep is the degree of blur, the larger the number, the blurrier it is.
Stroke: void imagetextouter (resource image, int size, int x, int y, string color, string fontfile, string text, string outercolor)
imagetextouter() draws the string text onto the image represented by image, starting from the coordinates x, y (the upper left corner is 0, 0), the color is color, and the color used for the border is outercolor, specified by fontfile truetype font file.
If no font file is specified, gd's internal font is used. Depending on the gd library used by php, if the fontfile does not start with '/', then '.ttf' will be appended to the file name and the library definition font path will be searched.
If a font file is specified, the coordinates represented by x,y define the base point of the first character (presumably the lower left corner of the character). Otherwise x,y define the upper right corner of the first character.
fontfile is the file name of the truetype font you want to use.
text is a text string that can contain utf-8 character sequences (of the form: {) to access more than the first 255 characters in the font.
color is the color in hexadecimal format #rrggbb, such as #ff0000 is red.
outercolor stroke color, hexadecimal #rrggbb format.
//用法示例:
header("content-type: image/png");
$im = imagecreatefromjpeg("bluesky.jpg");
$white = imagecolorallocate($im, 255,255,255);
imagetextouter($im, 9, 10, 20, '#000000', "simsun.ttc", '新年快乐', '#ffffff');
imagetextouter($im, 2, 10, 30, '#ffff00', "", 'hello, world!' , '#103993');
imagepng($im);
imagedestroy($im);
?>
希望本文所述对大家的PHP程序设计有所帮助。