<? Php Tutorial
/**
* Gd image mask
*
* @ Copyright ugia.cn
*/
Function imagemask (& $ im, $ x1, $ y1, $ x2, $ y2, $ deep)
{
For ($ x = $ x1; $ x <$ x2; $ x + = $ deep)
{
For ($ y = $ y1; $ y <$ y2; $ y + = $ deep)
{
$ Color = imagecolorat ($ im, $ x + round ($ deep/2), $ y + round ($ deep/2 ));
Imagefilledrectangle ($ im, $ x, $ y, $ x + $ deep, $ y + $ deep, $ color );
}
}
}
?>
Example:
<? Php
Header ("content-type: image/png ");
$ Im = imagecreatefromjpeg ("test.jpg ");
Imagemask ($ im, 57, 22,103, 40, 8 );
Imagepng ($ im );
Imagedestroy ($ im );
?>
<? Php
/**
* Gd image text outer
*
* @ Copyright ugia.cn
*/
Function imagetextouter (& $ im, $ size, $ x, $ y, $ color, $ fontfile, $ text, $ outer)
{
If (! Function_exists ('imagecolorallocatehex '))
{
Function imagecolorallocatehex ($ im, $ s)
{
If ($ s {0 }== "#") $ s = substr ($ s, 1 );
$ Bg_dec = hexdec ($ s );
Return imagecolorallocate ($ im,
($ Bg_dec & 0xff0000)> 16,
($ Bg_dec & 0x00ff00)> 8,
($ Bg_dec & 0x0000ff)
);
}
}
$ Ttf = false;
If (is_file ($ fontfile ))
{
$ Ttf = true;
$ Area = imagettfbbox ($ size, $ angle, $ fontfile, $ text );
$ Width = $ area [2]-$ area [0] + 2;
$ Height = $ area [1]-$ area [5] + 2;
}
Else
{
$ Width = strlen ($ text) * 10;
$ Height = 16;
}
$ Im_tmp = imagecreate ($ width, $ height );
$ White = imagecolorallocate ($ im_tmp, 255,255,255 );
$ Black = imagecolorallocate ($ im_tmp, 0, 0, 0 );
$ Color = imagecolorallocatehex ($ im, $ color );
$ Outer = imagecolorallocatehex ($ im, $ outer );
If ($ ttf)
{
Imagettftext ($ im_tmp, $ size, 0, 0, $ height-2, $ black, $ fontfile, $ text );
Imagettftext ($ im, $ size, 0, $ x, $ y, $ color, $ fontfile, $ text );
$ Y = $ y-$ height + 2;
}
Else
{
Imagestring ($ im_tmp, $ size, 0, 0, $ text, $ black );
Imagestring ($ im, $ size, $ x, $ y, $ text, $ color );
}
For ($ I = 0; $ I <$ width; $ I ++)
{
For ($ j = 0; $ j <$ height; $ j ++)
{
$ C = imagecolorat ($ im_tmp, $ I, $ j );
If ($ c! ==$ White)
{
Imagecolorat ($ im_tmp, $ I, $ j-1 )! = $ White | imagesetpixel ($ im, $ x + $ I, $ y + $ j-1, $ outer );
Imagecolorat ($ im_tmp, $ I, $ j + 1 )! = $ White | imagesetpixel ($ im, $ x + $ I, $ y + $ j + 1, $ outer );
Imagecolorat ($ im_tmp, $ I-1, $ j )! = $ White | imagesetpixel ($ im, $ x + $ I-1, $ y + $ j, $ outer );
Imagecolorat ($ im_tmp, $ I + 1, $ j )! = $ White | imagesetpixel ($ im, $ x + $ I + 1, $ y + $ j, $ outer );
// Cancel the annotation, which has the same luminous effect as fireworks.
/*
Imagecolorat ($ im_tmp, $ I-1, $ j-1 )! = $ White | imagesetpixel ($ im, $ x + $ I-1, $ y + $ j-1, $ outer );
Imagecolorat ($ im_tmp, $ I + 1, $ j-1 )! = $ White | imagesetpixel ($ im, $ x + $ I + 1, $ y + $ j-1, $ outer );
Imagecolorat ($ im_tmp, $ I-1, $ j + 1 )! = $ White | imagesetpixel ($ im, $ x + $ I-1, $ y + $ j + 1, $ outer );
Imagecolorat ($ im_tmp, $ I + 1, $ j + 1 )! = $ White | imagesetpixel ($ im, $ x + $ I + 1, $ y + $ j + 1, $ outer );
*/
}
}
}
Imagedestroy ($ im_tmp );
}
?>
Example:
<? Php
Header ("content-type: image/png ");
$ Im = imagecreatefromjpeg ("bluesky.jpg ");
$ White = imagecolorallocate ($ im, 255,255,255 );
Imagetextouter ($ im, 9, 10, 20, '#000000', "simsun. ttc", 'Happy New Year', '# ffff ');
Imagetextouter ($ im, 2, 10, 30, '# ffff00', "", 'Hello, world! ',' #103993 ');
Imagepng ($ im );
Imagedestroy ($ im );
?>
Mosaic: void imagemask (resource image, int x1, int y1, int x2, int y2, int deep)
Imagemask () adds mosaic to the rectangular area of the coordinate x1, y1 to x2, y2 (0 in the upper left corner of the image.
Deep indicates the degree of blurring, and the greater the number, the blurrier it.
Stroke: void imagetextouter (resource image, int size, int x, int y, string color, string fontfile, string text, string outercolor)
Imagetextouter () draws the string text to the image, starting from the coordinates x, y (0, 0 in the upper left corner). The color is color, and the border color is outercolor, use the truetype font file specified by fontfile.
If no font file is specified, the internal font of gd is used. Depending on the gd library used by php, if fontfile does not start with '/', '. Ttf' will be added to the file name and the library will be searched to define the font path.
If a font file is specified, the coordinates represented by x and y define the basic points of the first character (probably the lower left corner of the character ). Otherwise, x and y define the upper right corner of the first character.
Fontfile is the file name of the truetype font to be used.
Text is a text string that can contain UTF-8 character sequences (in the form of: {) to access more than the first 255 characters in the font.
Color is a hexadecimal # rrggbb color, for example, # ff0000 is red.
Outercolor stroke color, in hexadecimal # rrggbb format.