国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php生成藝術字體圖片水印代碼

2024-09-04 11:44:20
字體:
來源:轉載
供稿:網友
  1. //adv0.jpg就是背景圖片,注意函數與圖片格式對應    
  2. $im = imagecreatefromjpeg('/www/law/images/demo/adv0.jpg');     
  3. $font_color = imagecolorallocate ($im, 0, 250, 10); //這是文字顏色,綠色    
  4.    
  5. $text = "張三的博客";        //文字內容    
  6.    
  7. $font_file = "/www/font/hyi_xkj.ttf";     //字體的linux絕對路徑    
  8.    
  9. //26:字體, 0 是角度, 10,36是坐標, $font_color是文字色, font是字體,  文本是填入的文字    
  10. imagettftext($im, 26,0, 10, 36, $font_color ,$font_file$text);  往圖片插入文字    
  11.    
  12. // output image    
  13. header ('content-type: image/png');     //即便是從jpg拷貝的圖片,也能以png輸出,    
  14. imagepng ($im);    
  15. // clean up    
  16. imagedestroy($im); 
  17.   
  18. //生成水印方法二,代碼如下: 
  19.  
  20. public final class imageutils {  
  21. public imageutils() { 
  22.  
  23.  
  24. public final static string getpressimgpath(){  
  25. return applicationcontext.getrealpath("/template/data/util/shuiyin.gif");  
  26.  
  27. /**  
  28. * 把圖片印刷到圖片上  
  29. * @param pressimg -- 水印文件  
  30. * @param targetimg -- 目標文件  
  31. * @param x  
  32. * @param y  
  33. */  
  34. public final static void pressimage(string pressimg, string targetimg, int x, int y) {  
  35. try {  
  36. file _file = new file(targetimg);  
  37. image src = imageio.read(_file);  
  38. int wideth = src.getwidth(null);  
  39. int height = src.getheight(null);  
  40. bufferedimage image = new bufferedimage(wideth, height,  
  41. bufferedimage.type_int_rgb);  
  42. graphics g = image.creategraphics();  
  43. g.drawimage(src, 0, 0, wideth, height, null); 
  44.  
  45. // 水印文件  
  46. file _filebiao = new file(pressimg);  
  47. image src_biao = imageio.read(_filebiao);  
  48. int wideth_biao = src_biao.getwidth(null);  
  49. int height_biao = src_biao.getheight(null);  
  50. g.drawimage(src_biao, wideth - wideth_biao - x, height - height_biao -y, wideth_biao,  
  51. height_biao, null);  
  52. // /  
  53. g.dispose();  
  54. fileoutputstream out = new fileoutputstream(targetimg);  
  55. jpegimageencoder encoder = jpegcodec.createjpegencoder(out);  
  56. encoder.encode(image);  
  57. out.close();  
  58. } catch (exception e) {  
  59. e.printstacktrace();  
  60. }  
  61.  
  62. /**  
  63. * 打印文字水印圖片  
  64. * @param presstext --文字  
  65. * @param targetimg -- 目標圖片  
  66. * @param fontname -- 字體名  
  67. * @param fontstyle -- 字體樣式  
  68. * @param color -- 字體顏色  
  69. * @param fontsize -- 字體大小  
  70. * @param x -- 偏移量  
  71. * @param y  
  72. */ 
  73.  
  74. public static void presstext(string presstext, string targetimg, string fontname,int fontstyle, int color, int fontsize, int x, int y) {  
  75. try {  
  76. file _file = new file(targetimg);  
  77. image src = imageio.read(_file);  
  78. int wideth = src.getwidth(null);  
  79. int height = src.getheight(null);  
  80. bufferedimage image = new bufferedimage(wideth, height,  
  81. bufferedimage.type_int_rgb);  
  82. graphics g = image.creategraphics();  
  83. g.drawimage(src, 0, 0, wideth, height, null);  
  84. // string s=www.111cn.net;  
  85. g.setcolor(color.red);  
  86. g.setfont(new font(fontname, fontstyle, fontsize)); 
  87.  
  88.  
  89. g.drawstring(presstext, wideth - fontsize - x, height - fontsize/2 - y);  
  90. g.dispose();  
  91. fileoutputstream out = new fileoutputstream(targetimg);  
  92. jpegimageencoder encoder = jpegcodec.createjpegencoder(out);  
  93. encoder.encode(image);  
  94. out.close();  
  95. } catch (exception e) {  
  96. system.out.println(e);  
  97. }  
  98. //開源代碼Vevb.com 
  99. public static void main(string[] args) {  
  100. pressimage("c:/shuiyin/shuiyin.gif""c:/shuiyin/dsc02342.jpg", 20 ,20);  
  101. }  

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 独山县| 大姚县| 云安县| 云浮市| 日土县| 扎赉特旗| 苏尼特左旗| 临泉县| 辽阳县| 金溪县| 锦州市| 苏尼特右旗| 高雄县| 康定县| 尉氏县| 九龙城区| 甘洛县| 巴马| 容城县| 宿松县| 沙雅县| 象州县| 稷山县| 平远县| 平利县| 池州市| 龙口市| 广水市| 周至县| 页游| 吉水县| 理塘县| 揭东县| 郎溪县| 正镶白旗| 英吉沙县| 双柏县| 安阳市| 交口县| 白山市| 天全县|