{"id":46835,"date":"2024-12-02T08:19:18","date_gmt":"2024-12-02T00:19:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46835\/"},"modified":"2024-12-02T08:19:18","modified_gmt":"2024-12-02T00:19:18","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e5%9b%be%e5%83%8f%e6%93%8d%e4%bd%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46835\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p>PHP \u4e3a\u56fe\u50cf\u5904\u7406\u63d0\u4f9b\u51fd\u6570\uff0c\u5305\u62ec\u8c03\u6574\u5927\u5c0f\u3001\u88c1\u526a\u3001\u65cb\u8f6c\u548c\u6dfb\u52a0\u6587\u672c\u3002\u5e38\u7528\u51fd\u6570\u5305\u62ec\uff1aimagecreatefromjpeg() \u521b\u5efa\u56fe\u50cf\u8d44\u6e90\u3001imagecopyresized() \u8c03\u6574\u5927\u5c0f\u3001imagecrop() \u88c1\u526a\u3001imagerotate() \u65cb\u8f6c\u3001imagetext() \u6dfb\u52a0\u6587\u672c\u3002\u5b9e\u6218\u6848\u4f8b\uff1a\u901a\u8fc7\u8c03\u6574\u56fe\u50cf\u5927\u5c0f\u521b\u5efa\u7f29\u7565\u56fe\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729849355671b680b89897.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\uff1a\u56fe\u50cf\u64cd\u4f5c\u6307\u5357<\/strong><\/p>\n<p>PHP \u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\u6765\u9ad8\u6548\u5730\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\u3002\u8fd9\u4e9b\u51fd\u6570\u4f7f\u60a8\u53ef\u4ee5\u8f7b\u677e\u6267\u884c\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u4f8b\u5982\u8c03\u6574\u5927\u5c0f\u3001\u88c1\u526a\u3001\u65cb\u8f6c\u548c\u6dfb\u52a0\u6587\u672c\u3002<\/p>\n<p><strong>\u5b89\u88c5 GD \u5e93<\/strong><\/p>\n<p>\u8981\u4f7f\u7528 PHP \u7684\u56fe\u50cf\u64cd\u4f5c\u51fd\u6570\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5 GD \u5e93\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a<\/p>\n<pre>sudo apt-get install php-gd<\/pre>\n<p><strong>\u5e38\u7528\u56fe\u50cf\u5904\u7406\u51fd\u6570<\/strong><\/p>\n<p><strong>1. imagecreatefromjpeg()<\/strong><\/p>\n<pre>$image = imagecreatefromjpeg('image.jpg');<\/pre>\n<p><strong>2. imagecopyresized()<\/strong><\/p>\n<pre>imagecopyresized($destination, $source, 0, 0, 0, 0, 100, 100, 200, 200);<\/pre>\n<p><strong>3. imagecrop()<\/strong><\/p>\n<pre>$crop_image = imagecrop($image, ['x' =&gt; 10, 'y' =&gt; 10, 'width' =&gt; 150, 'height' =&gt; 150]);<\/pre>\n<p><strong>4. imagerotate()<\/strong><\/p>\n<pre>$rotated_image = imagerotate($image, 45, 0);<\/pre>\n<p><strong>5. imagetext()<\/strong><\/p>\n<pre>imagetext($image, 5, 10, 10, 'Hello World', 0x000000);<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u521b\u5efa\u7f29\u7565\u56fe<\/strong><\/p>\n<pre>\/\/ \u4ece\u539f\u59cb\u56fe\u50cf\u521b\u5efa\u56fe\u50cf\u8d44\u6e90\n$source_image = imagecreatefromjpeg('image.jpg');\n\n\/\/ \u521b\u5efa\u7f29\u7565\u56fe\u7684\u753b\u5e03\n$thumb_image = imagecreatetruecolor(150, 150);\n\n\/\/ \u8c03\u6574\u56fe\u50cf\u5927\u5c0f\nimagecopyresized($thumb_image, $source_image, 0, 0, 0, 0, 150, 150, imageSX($source_image), imageSY($source_image));\n\n\/\/ \u8f93\u51fa\u7f29\u7565\u56fe\nheader('Content-Type: image\/jpeg');\nimagejpeg($thumb_image);<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\uff1f\u300b\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01 PHP \u4e3a\u56fe\u50cf\u5904\u7406\u63d0\u4f9b\u51fd\u6570\uff0c\u5305\u62ec\u8c03\u6574\u5927\u5c0f\u3001\u88c1\u526a\u3001\u65cb\u8f6c\u548c\u6dfb\u52a0\u6587\u672c\u3002\u5e38\u7528\u51fd\u6570\u5305\u62ec\uff1aimagecreatefromjpeg() \u521b\u5efa\u56fe\u50cf\u8d44\u6e90\u3001imagecopyresized() \u8c03\u6574\u5927\u5c0f\u3001imagecrop() \u88c1\u526a\u3001imagerotate() \u65cb\u8f6c\u3001imagetext() \u6dfb\u52a0\u6587\u672c\u3002\u5b9e\u6218\u6848\u4f8b\uff1a\u901a\u8fc7\u8c03\u6574\u56fe\u50cf\u5927\u5c0f\u521b\u5efa\u7f29\u7565\u56fe\u3002 PHP \u51fd\u6570\uff1a\u56fe\u50cf\u64cd\u4f5c\u6307\u5357 PHP \u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\u6765\u9ad8\u6548\u5730\u5904\u7406\u56fe\u50cf\u64cd\u4f5c\u3002\u8fd9\u4e9b\u51fd\u6570\u4f7f\u60a8\u53ef\u4ee5\u8f7b\u677e\u6267\u884c\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u4f8b\u5982\u8c03\u6574\u5927\u5c0f\u3001\u88c1\u526a\u3001\u65cb\u8f6c\u548c\u6dfb\u52a0\u6587\u672c\u3002 \u5b89\u88c5 GD \u5e93 \u8981\u4f7f\u7528 PHP \u7684\u56fe\u50cf\u64cd\u4f5c\u51fd\u6570\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5 GD \u5e93\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b8c\u6210\uff1a sudo apt-get install php-gd \u5e38\u7528\u56fe\u50cf\u5904\u7406\u51fd\u6570 1. imagecreatefromjpeg() $image = imagecreatefromjpeg(&#8216;image.jpg&#8217;); 2. imagecopyresized() imagecopyresized($destination, $source, 0, 0, 0, 0, 100, 100, 200, 200); 3. imagecrop() $crop_image = imagecrop($image, [&#8216;x&#8217; =&gt; 10, &#8216;y&#8217; =&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-46835","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=46835"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46835\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}