- /**
- * GD image text outer
- *
- * @ Copyright UGiA. CN
- * [Url = home. php? Mod = space & uid = 17823] @ LINK [/url] www.ugia.cn /? P = 88
- * @ Edit bbs.it-home.org
- */
- 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 );
- }
- ?>
2. call example:
- 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 () converts coordinates x1, y1 to x2, add mosaic to the rectangular area of y2 (0, 0 in the upper left corner of the image. Deep indicates the degree of blurring, and the greater the number, the blurrier it. Effect, such: 1. mosaic function code:
- /**
- * GD image mask
- *
- * @ Edit bbs.it-home.org
- */
- 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 );
- }
- }
- }
- ?>
2. call example:
- Header ("Content-type: image/png ");
- $ Im = imagecreatefromjpeg ("test.jpg ");
- Imagemask ($ im, 57, 22,103, 40, 8 );
- Imagepng ($ im );
- Imagedestroy ($ im );
- ?>
|