{"id":611,"date":"2023-02-26T10:50:52","date_gmt":"2023-02-26T02:50:52","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=611"},"modified":"2023-04-29T20:22:46","modified_gmt":"2023-04-29T12:22:46","slug":"php-generate-rounded-images-with-text","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/php-generate-rounded-images-with-text\/","title":{"rendered":"PHP\u751f\u6210\u5e26\u6587\u5b57\u5706\u89d2\u56fe\u7247"},"content":{"rendered":"<p>\u4f7f\u7528PHP GD\u5e93\u51fd\u6570\u751f\u6210\u5e26\u6587\u5b57\u56fe\u7247\uff0cCSS3\u7684border-radius\u4e3a\u5143\u7d20\u6dfb\u52a0\u5706\u89d2\u8fb9\u6846\u3002<\/p>\n<p>image.php<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-php\">&lt;?php\n    \/\/1.\u521b\u5efa\u753b\u5e03\n    $img = imagecreatetruecolor(120, 120);\n\n    \/\/2.\u80cc\u666f\u989c\u8272\n    $color = imagecolorallocate($img, 0, 184, 212);\n\n    \/\/3.\u586b\u5145\u80cc\u666f\u989c\u8272\n    imagefill($img, 0, 0, $color);\n\n    \/\/4.\u5199\u5b57\u7b26\u4e32(\u5b57\u6bcd)\n    \/\/$str = substr(str_shuffle(&#039;ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789&#039;), 0, 4);\n    \/\/imagestring($img, 5, 5, 5, $str, $red);\n\n    \/\/5.\u5199\u5b57\u7b26\u4e32\n    $text = &#039;\u4f1a&#039;;\n    if (preg_match(&#039;\/^[\\x{4e00}-\\x{9fa5}]\/u&#039;, $text)) { \/\/\u4e2d\u6587\n        $left = 20;\n        $top = 88;\n        $size = 60;\n    } else if (preg_match(&#039;\/^[a-zA-Z]$\/&#039;, $text) || preg_match(&#039;\/^[0-9]$\/&#039;, $text)) { \/\/\u6570\u5b57\u548c\u5b57\u6bcd\n        $left = 26;\n        $top = 95;\n        $size = 72;\n    }\n    $text_color = imagecolorallocate($img, 255, 255, 255);\n    imagettftext($img, $size, 0, $left, $top, $text_color, &#039;.\/msyh.ttf&#039;, $text);\n\n    \/\/6.\u8f93\u51fa\u56fe\u7247\n    header(&#039;content-type:image\/png&#039;);\n    imagepng($img);\n    \/\/imagepng($img, date(&quot;Ymd_His&quot;) . &#039;.png&#039;);\n\n    \/\/7.\u9500\u6bc1\u753b\u5e03\n    imagedestroy($img);\n<\/code><\/pre>\n<p>index.php<\/p>\n<pre><code class=\"language-php\">&lt;image style=&quot;border-radius:20px;&quot; src=&quot;image.php&quot; \/&gt;<\/code><\/pre>\n<p>\u9884\u89c8<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/PHP\/PHP_RoundImage.png\" alt=\"image\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528PHP GD\u5e93\u51fd\u6570\u751f\u6210\u5e26\u6587\u5b57\u56fe\u7247\uff0cCSS3\u7684border-radius\u4e3a\u5143\u7d20\u6dfb\u52a0\u5706\u89d2\u8fb9\u6846\u3002 image.p [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-611","post","type-post","status-publish","format-standard","hentry","category-php-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=611"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/611\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}