{"id":649,"date":"2012-05-15T16:42:29","date_gmt":"2012-05-15T08:42:29","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=649"},"modified":"2012-05-15T17:44:39","modified_gmt":"2012-05-15T09:44:39","slug":"649","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/649","title":{"rendered":"php\u4e2dgd\u5e93Could not find\/open font \u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"

\u60f3\u8981\u4e3a\u6211\u7684\u641e\u7b11\u56fe\u7247\u7ad9<\/a>\uff1ahttp:\/\/www.nbqq.net\/gaoxiao<\/a> \u52a0\u4e00\u4e2a\u56fe\u7247\u4e0a\u4f20\u6c34\u5370\u51fd\u6570\uff0c\u767e\u5ea6\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u611f\u89c9\u4e0d\u9519\uff01\u53ef\u662f\u9047\u5230\u4e86\u95ee\u9898\uff0c\u4e0d\u8fc7\u6700\u7ec8\u89e3\u51b3\u4e86\u3002<\/p>\n

Warning<\/strong>: imagettfbbox() [function.imagettfbbox<\/a>]: Could not find\/open font in \/home\/admin\/nbqq.net\/test\/watermark.php<\/strong> on line 30<\/strong><\/p>\n

Warning<\/strong>: imagettftext() [function.imagettftext<\/a>]: Could not find\/open font in \/home\/admin\/nbqq.net\/test\/watermark.php<\/strong> on line 66<\/strong><\/p>\n

Warning<\/strong>: imagettftext() [function.imagettftext<\/a>]: Could not find\/open font in \/home\/admin\/nbqq.net\/test\/watermark.php<\/strong> on line 83<\/strong><\/p>\n

Warning<\/strong>: imagettftext() [function.imagettftext<\/a>]: Could not find\/open font in \/home\/admin\/nbqq.net\/test\/watermark.php<\/strong> on line 87<\/strong><\/p>\n

Warning<\/strong>: imagettftext() [function.imagettftext<\/a>]: Could not find\/open font in \/home\/admin\/nbqq.net\/test\/watermark.php<\/strong> on line 89<\/strong><\/p><\/blockquote>\n

\u00a0\u539f\u56e0\u662f\u8fd9\u53e5\uff1aaddchartopic( “image.png”,50,20,”I’m here as always”,15, “simsun.ttc”, “ffffff”, “test1.png”, “cccccc”,5, “simsun.ttc” );<\/p>\n

\u4e2d\u7684\u5b57\u5e93\u6ca1\u6709\u6307\u5b9a\u3002<\/p>\n

\u89e3\u51b3\u529e\u6cd5\uff1a\u5c06C:\\WINDOWS\\Fonts\u4e2d\u60a8\u6240\u8981\u91c7\u7528\u7684\u5b57\u5e93\u6587\u4ef6\u4e0a\u4f20\u81f3php\u811a\u672c\u7a0b\u5e8f\u540c\u76ee\u5f55\u4e0b\u5373\u53ef\uff01\uff01<\/p>\n

\u4e0b\u9762\u5e16\u51fa\u51fd\u6570\uff1a<\/p>\n

———————————————————-<\/p>\n

<?
\n\/*
\n\u53c2\u6570\uff1a
\n1.$bgimg : \u80cc\u666f\u56fe\u7247
\n2.$x\u00a0\u00a0\u00a0\u00a0 : \u8ddd\u79bb\u5de6\u8fb9\u7684\u8ddd\u79bb
\n3.$topy\u00a0 : \u8ddd\u79bb\u9876\u90e8\u7684\u8ddd\u79bb
\n4.$font\u00a0 : \u8981\u6dfb\u52a0\u7684\u5b57\u7b26\u4e32
\n5.$size\u00a0 : \u5b57\u4f53\u7684\u5927\u5c0f
\n6.$fonttype : \u5b57\u4f53
\n7.$color : \u5b57\u4f53\u989c\u8272
\n8.$tofile: \u751f\u6210\u7684\u56fe\u7247
\n9.$nameyycolor : \u5b57\u7b26\u4e32\u7684\u9634\u5f71\u989c\u8272
\n10.$nameyysize : \u9634\u5f71\u7684\u5bbd\u5ea6
\n11.$fontfile\u00a0\u00a0 : \u5b57\u4f53\u6587\u4ef6
\n*\/
\nfunction addchartopic( $bgimg, $x, $topy, $font, $size, $fonttype, $color, $tofile, $nameyycolor, $nameyysize, $fontfile )
\n{
\n\u00a0\u00a0$r = hexdec( substr( $color, 0, 2 ) );\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0
\n\u00a0\u00a0\/*hexdec()\u51fd\u6570\u628a\u5341\u516d\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u3002*\/
\n\u00a0\u00a0$g = hexdec( substr( $color, 2, 2 ) );
\n\u00a0\u00a0$b = hexdec( substr( $color, 4, 2 ) );
\n\u00a0\u00a0$im = imagecreatefrompng( $bgimg );
\n\u00a0\u00a0\/*ImageCreateFromPNG\u672c\u51fd\u6570\u7528\u6765\u53d6\u51fa\u4e00\u5f20 PNG\u683c\u5f0f\u56fe\u5f62\uff0c\u901a\u5f53\u53d6\u51fa\u5f53\u80cc\u666f\u6216\u8005\u57fa\u672c\u7684\u753b\u5e03\u6837\u672c\u4f7f\u7528\u3002\u53c2\u6570 filename \u53ef\u4ee5\u662f\u672c\u5730\u7aef\u7684\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u662f\u7f51\u7edc\u7684 URL\u4f4d\u5740\u3002ImageCreateFromPNG\u8fd4\u56de\u503c\u4e3a PNG \u7684\u6587\u4ef6\u4ee3\u7801\uff0c\u53ef\u4f9b\u5176\u5b83\u7684\u51fd\u6570\u4f7f\u7528\u3002\u672c\u51fd\u6570\u5728 PHP 3.0.13 \u7248\u4e4b\u540e\u624d\u652f\u6301\u3002
\n*\/
\n\u00a0\u00a0$fontcolor = imagecolorallocate( $im, $r, $g, $b );
\n\u00a0\u00a0\/*int imagecolorallocate ( resource image, int red, int green, int blue)
\n\u3000\u3000imagecolorallocate() \u8fd4\u56de\u4e00\u4e2a\u6807\u8bc6\u7b26\uff0c\u4ee3\u8868\u4e86\u7531\u7ed9\u5b9a\u7684 RGB \u6210\u5206\u7ec4\u6210\u7684\u989c\u8272\u3002image \u53c2\u6570\u662f imagecreate() \u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002red\uff0cgreen \u548c blue \u5206\u522b\u662f\u6240\u9700\u8981\u7684\u989c\u8272\u7684\u7ea2\uff0c\u7eff\uff0c\u84dd\u6210\u5206\u3002\u8fd9\u4e9b\u53c2\u6570\u662f 0 \u5230 255 \u7684\u6574\u6570\u6216\u8005\u5341\u516d\u8fdb\u5236\u7684 0x00 \u5230 0xFF\u3002imagecolorallocate() \u5fc5\u987b\u88ab\u8c03\u7528\u4ee5\u521b\u5efa\u6bcf\u4e00\u79cd\u7528\u5728 image \u6240\u4ee3\u8868\u7684\u56fe\u50cf\u4e2d\u7684\u989c\u8272\u3002 *\/
\n\u00a0\u00a0$sy = imagesy( $im ) \/ $topy;
\n\u00a0\u00a0\/*imagesx\u4e0eimagesy– \u5206\u522b\u53d6\u5f97\u56fe\u50cf\u5bbd\u5ea6\u4e0e\u9ad8\u5ea6\u3002*\/
\n\u00a0\u00a0$array = imagettfbbox( $size, 0, $fontfile, $font );
\n\u00a0\u00a0\/*array imagettfbbox (int size, int angle, string fontfile, string text)
\n\u00a0\u00a0\u8bf4\u660e :<\/p>\n

\u00a0\u00a0\u6b64\u51fd\u5f0f\u8ba1\u7b97\u5e76\u4f20\u56deTrueType\u6587\u5b57\u7684\u533a\u5757\u5750\u6807\u3002
\n\u00a0\u00a0text : \u8981\u88ab\u6d4b\u91cf\u7684\u5b57\u4e32\u3002
\n\u00a0\u00a0size : \u5b57\u4f53\u5927\u5c0f\u3002
\n\u00a0\u00a0fontfile : TrueType\u5b57\u4f53\u6863\u7684\u540d\u79f0(\u4e5f\u53ef\u4ee5\u662fURL)\u3002
\n\u00a0\u00a0angle : text\u5c06\u8981\u6d4b\u91cf\u7684\u89d2\u5ea6\u5ea6\u6570\u3002
\n\u00a0\u00a0ImageTTFBBox( )\u4f20\u56de\u7684\u9635\u5217\u67098\u4e2a\u5143\u7d20\uff0c\u4ee3\u8868\u6587\u5b57\u533a\u5757\u7684\u56db\u4e2a\u9876\u70b9\u3002
\n\u00a0\u00a00 \u5de6\u4e0b\u89d2X\u5750\u6807
\n\u00a0\u00a01 \u5de6\u4e0b\u89d2Y\u5750\u6807
\n\u00a0\u00a02 \u53f3\u4e0b\u89d2X\u5750\u6807
\n\u00a0\u00a03 \u53f3\u4e0b\u89d2Y\u5750\u6807
\n\u00a0\u00a04 \u53f3\u4e0a\u89d2X\u5750\u6807
\n\u00a0\u00a05 \u53f3\u4e0a\u89d2Y\u5750\u6807
\n\u00a0\u00a06 \u5de6\u4e0a\u89d2X\u5750\u6807
\n\u00a0\u00a07 \u5de6\u4e0a\u89d2Y\u5750\u6807
\n\u00a0\u00a0\u9876\u70b9\u662f\u76f8\u5bf9\u4e8etext\uff0c\u6240\u4ee5\u4e0d\u7ba1\u89d2\u5ea6\u3002”\u5de6\u4e0a\u89d2”\u7684\u610f\u601d\u662f\uff0c\u4ee5\u6c34\u5e73\u7684\u65b9\u5411\u770b\u6587\u5b57\u65f6\u7684\u5de6\u4e0a\u89d2\u3002
\n*\/
\n\u00a0\u00a0$fontsy = ( $array[0] – $array[5] ) \/ 2;
\n\u00a0\u00a0$jiaozhen = $fontsy * 0.3;
\n\u00a0\u00a0$y = $sy + $fontsy – $jiaozhen;
\n\u00a0\u00a0if ( $x == “-1” )
\n\u00a0\u00a0{
\n\u00a0\u00a0\u00a0\u00a0$sx = imagesx( $im ) \/ 2;
\n\u00a0\u00a0\u00a0\u00a0$array = imagettfbbox( $size, 0, $fontfile, $font );
\n\u00a0\u00a0\u00a0\u00a0$fontsx = ( $array[0] – $array[2] ) \/ 2;
\n\u00a0\u00a0\u00a0\u00a0$x = $sx + $fontsx;
\n\u00a0\u00a0}
\n\u00a0\u00a0$r1 = hexdec( substr( $nameyycolor, 0, 2 ) );
\n\u00a0\u00a0$g1 = hexdec( substr( $nameyycolor, 2, 2 ) );
\n\u00a0\u00a0$b1 = hexdec( substr( $nameyycolor, 4, 2 ) );
\n\u00a0\u00a0$yycolor = imagecolorallocate( $im, $r1, $g1, $b1 );
\n\u00a0\u00a0if ( 2 < $nameyysize )
\n\u00a0\u00a0{
\n\u00a0\u00a0\u00a0\u00a0imagettftext( $im, $size, 0, $x + 3, $y + 3, $yycolor, $fontfile, $font );
\n\u00a0\u00a0\u00a0\u00a0\/*imagettftext (image,size,angle, x, y,color,fontfile,text)<\/p>\n

\u610f\u601d\u662f imagettftext() \u5c06\u5b57\u7b26\u4e32 text \u753b\u5230 image \u6240\u4ee3\u8868\u7684\u56fe\u50cf\u4e0a\uff0c\u4ece\u5750\u6807 x\uff0cy\uff08\u5de6\u4e0a\u89d2\u4e3a 0, 0\uff09\u5f00\u59cb\uff0c\u89d2\u5ea6\u4e3a angle\uff0c\u989c\u8272\u4e3a color\uff0c\u4f7f\u7528 fontfile \u6240\u6307\u5b9a\u7684 TrueType \u5b57\u4f53\u6587\u4ef6\u3002\u6839\u636e PHP \u6240\u4f7f\u7528\u7684 GD \u5e93\u7684\u4e0d\u540c\uff0c\u5982\u679c fontfile \u6ca1\u6709\u4ee5 ‘\/’\u5f00\u5934\uff0c\u5219 ‘.ttf’ \u5c06\u88ab\u52a0\u5230\u6587\u4ef6\u540d\u4e4b\u540e\u5e76\u4e14\u4f1a\u641c\u7d22\u5e93\u5b9a\u4e49\u5b57\u4f53\u8def\u5f84\u3002<\/p>\n

\u7531 x\uff0cy \u6240\u8868\u793a\u7684\u5750\u6807\u5b9a\u4e49\u4e86\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u57fa\u672c\u70b9\uff08\u5927\u6982\u662f\u5b57\u7b26\u7684\u5de6\u4e0b\u89d2\uff09\u3002\u8fd9\u548c imagestring() \u4e0d\u540c\uff0c\u5176 x\uff0cy \u5b9a\u4e49\u4e86\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u53f3\u4e0a\u89d2\u3002<\/p>\n

angle \u4ee5\u89d2\u5ea6\u8868\u793a\uff0c0 \u5ea6\u4e3a\u4ece\u5de6\u5411\u53f3\u9605\u8bfb\u6587\u672c\uff083 \u70b9\u949f\u65b9\u5411\uff09\uff0c\u66f4\u9ad8\u7684\u503c\u8868\u793a\u9006\u65f6\u9488\u65b9\u5411\uff08\u5373\u5982\u679c\u503c\u4e3a 90 \u5219\u8868\u793a\u4ece\u4e0b\u5411\u4e0a\u9605\u8bfb\u6587\u672c\uff09\u3002<\/p>\n

fontfile \u662f\u60f3\u8981\u4f7f\u7528\u7684 TrueType \u5b57\u4f53\u7684\u6587\u4ef6\u540d\u3002<\/p>\n

text \u662f\u6587\u672c\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u5305\u542b utf-8 \u5b57\u7b26\u5e8f\u5217\uff08\u5f62\u5f0f\u4e3a\uff1a&#123;\uff09\u6765\u8bbf\u95ee\u5b57\u4f53\u4e2d\u8d85\u8fc7\u524d 255 \u4e2a\u7684\u5b57\u7b26\u3002<\/p>\n

color \u662f\u989c\u8272\u7684\u7d22\u5f15\u503c\u3002\u4f7f\u7528\u67d0\u989c\u8272\u7d22\u5f15\u503c\u7684\u8d1f\u503c\u5177\u6709\u5173\u95ed\u9632\u6df7\u8272\u7684\u6548\u679c*\/
\n\u00a0\u00a0}
\n\u00a0\u00a0if ( 1 < $nameyysize )
\n\u00a0\u00a0{
\n\u00a0\u00a0\u00a0\u00a0imagettftext( $im, $size, 0, $x + 2, $y + 2, $yycolor, $fontfile, $font );
\n\u00a0\u00a0}
\n\u00a0\u00a0if ( 0 < $nameyysize )
\n\u00a0\u00a0{
\n\u00a0\u00a0\u00a0\u00a0imagettftext( $im, $size, 0, $x + 1, $y + 1, $yycolor, $fontfile, $font );
\n\u00a0\u00a0}
\n\u00a0\u00a0imagettftext( $im, $size, 0, $x, $y, $fontcolor, $fontfile, $font );
\n\u00a0\u00a0imagepng( $im, $tofile );\/*\u672c\u51fd\u6570\u7528\u6765\u5efa\u7acb\u4e00\u5f20 PNG \u683c\u5f0f\u56fe\u5f62\u3002\u53c2\u6570 im \u4e3a\u4f7f\u7528 ImageCreate() \u6240\u5efa\u7acb\u7684\u56fe\u7247\u4ee3\u7801\u3002\u53c2\u6570 filename \u53ef\u7701\u7565\uff0c\u82e5\u65e0\u672c\u53c2\u6570 filename\uff0c\u5219\u4f1a\u5c06\u56fe\u7247\u6307\u63a5\u9001\u5230\u6d4f\u89c8\u5668\u7aef\uff0c\u8bb0\u5f97\u5728\u9001\u51fa\u56fe\u7247\u4e4b\u524d\u8981\u5148\u9001\u51fa\u4f7f\u7528 Content-type: image\/png \u7684\u6807\u5934\u5b57\u7b26\u4e32 (header) \u5230\u6d4f\u89c8\u5668\u7aef\uff0c\u4ee5\u987a\u5229\u4f20\u8f93\u56fe\u7247\u3002\u672c\u51fd\u6570\u5728 PHP 3.0.13 \u7248\u4e4b\u540e\u624d\u652f\u6301\u3002 *\/
\n\u00a0\u00a0imagedestroy( $im );
\n\u00a0\u00a0\/*bool imagedestroy ( resource image )
\nimagedestroy() \u91ca\u653e\u4e0e image \u5173\u8054\u7684\u5185\u5b58
\n*\/
\n\u00a0\u00a0chmod( $tofile, 438 );
\n}<\/p>\n

addchartopic( “image.png”,50,20,”I’m here as always”,15, “simsun.ttc”, “ffffff”, “test1.png”, “cccccc”,5, “simsun.ttc” );
\necho “<h2>*This is the original png image:<\/h2>”;
\necho “<hr><center><img src=test.png border=1><\/center>”;
\necho “<h2>*This is the new png image:<\/h2>”;
\necho “<hr><center><img src=test1.png border=1><\/center>”;<\/p>\n

?><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u60f3\u8981\u4e3a\u6211\u7684\u641e\u7b11\u56fe\u7247\u7ad9\uff1ahttp:\/\/www.nbqq.net\/gaoxiao \u52a0\u4e00\u4e2a\u56fe\u7247\u4e0a\u4f20\u6c34\u5370\u51fd\u6570\uff0c\u767e\u5ea6\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u611f\u89c9\u4e0d\u9519\uff01\u53ef\u662f\u9047\u5230\u4e86\u95ee\u9898\uff0c\u4e0d\u8fc7\u6700\u7ec8\u89e3\u51b3\u4e86\u3002 Warning: imagettfbbox() [function.imagettfbbox]: Could not find\/open font in \/home\/admin\/nbqq.net\/test\/watermark.php on line 30 Warning: imagettftext() [function.imagettftext]: Could not find\/open font in \/home\/admin\/nb<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/649"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=649"}],"version-history":[{"count":4,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/649\/revisions"}],"predecessor-version":[{"id":652,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/649\/revisions\/652"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=649"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}