{"id":199383,"date":"2025-05-03T11:41:26","date_gmt":"2025-05-03T03:41:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199383\/"},"modified":"2025-05-03T11:41:26","modified_gmt":"2025-05-03T03:41:26","slug":"%e7%bb%99ecshop%e7%bc%96%e8%be%91%e5%99%a8kindeditor%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%e6%b7%bb%e5%8a%a0%e6%b0%b4%e5%8d%b0%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199383\/","title":{"rendered":"\u7ed9ecshop\u7f16\u8f91\u5668kindeditor\u56fe\u7247\u4e0a\u4f20\u6dfb\u52a0\u6c34\u5370\u529f\u80fd"},"content":{"rendered":"<p> \u597d\u6a21\u677f\u4ee5\u524d\u5728\u7f51\u7ad9\u4ecb\u7ecd\u8fc7ecshop\u66f4\u6362\u7f16\u8f91\u6210kindeditor\u7684\u65b9\u6cd5\uff0c\u4f46\u662f\u4e0a\u4f20\u7684\u56fe\u7247\u4e0d\u80fd\u81ea\u52a8\u589e\u52a0\u6c34\u5370\uff0c\u4eca\u5929\u628a\u76f8\u5e94\u65b9\u6cd5\u544a\u8bc9\u5927\u5bb6\uff1a<\/p>\n<p> \u5728kindeditor\/php\/upload_json.php\u4e2d\uff0c\u6709\u4e24\u5904\u9700\u8981\u4fee\u6539\u7684\u5730\u65b9\u3002<\/p>\n<p> \u7b2c\u4e00\u6b65\uff0c\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4e00\u4e2a\u65b9\u6cd5<\/p>\n<p> function imageWaterMark($groundImage, $waterPos=0, $waterImage=&#8221;, $alpha=80, $waterText=&#8221;, $textFont=9, $textColor=&#8217;#FF0000&#8242;){<br \/> &nbsp; &nbsp; $isWaterImage = FALSE;<br \/> &nbsp; &nbsp; $formatMsg = &#8216;\u4e0d\u652f\u6301\u8be5\u56fe\u7247\u683c\u5f0f\uff01\u8bf7\u4f7f\u7528GIF\u3001JPG\u3001PNG\u683c\u5f0f\u7684\u56fe\u7247\u3002&#8217;;<br \/> &nbsp; &nbsp; \/\/\u8bfb\u53d6\u6c34\u5370\u6587\u4ef6<br \/> &nbsp; &nbsp; if(!empty($waterImage) &amp;&amp; file_exists($waterImage)){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $isWaterImage = TRUE;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $water_info = getimagesize($waterImage);<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $water_w = $water_info[0];\/\/\u53d6\u5f97\u6c34\u5370\u56fe\u7247\u7684\u5bbd<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $water_h = $water_info[1];\/\/\u53d6\u5f97\u6c34\u5370\u56fe\u7247\u7684\u9ad8<br \/> &nbsp; &nbsp; &nbsp; &nbsp; switch($water_info[2]){\/\/\u53d6\u5f97\u6c34\u5370\u56fe\u7247\u7684\u683c\u5f0f<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:$water_im = imagecreatefromgif($waterImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:$water_im = imagecreatefromjpeg($waterImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:$water_im = imagecreatefrompng($waterImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:die($formatMsg);<br \/> &nbsp; &nbsp; &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; \/\/\u8bfb\u53d6\u80cc\u666f\u56fe\u7247<br \/> &nbsp; &nbsp; if(!empty($groundImage) &amp;&amp; file_exists($groundImage)){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $ground_info = getimagesize($groundImage);<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $ground_w = $ground_info[0];\/\/\u53d6\u5f97\u80cc\u666f\u56fe\u7247\u7684\u5bbd<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $ground_h = $ground_info[1];\/\/\u53d6\u5f97\u80cc\u666f\u56fe\u7247\u7684\u9ad8<br \/> &nbsp; &nbsp; &nbsp; &nbsp; switch($ground_info[2]){\/\/\u53d6\u5f97\u80cc\u666f\u56fe\u7247\u7684\u683c\u5f0f<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:$ground_im = imagecreatefromgif($groundImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:$ground_im = imagecreatefromjpeg($groundImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:$ground_im = imagecreatefrompng($groundImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:die($formatMsg);<br \/> &nbsp; &nbsp; &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; }else{<br \/> &nbsp; &nbsp; &nbsp; &nbsp; alert(&#8220;\u6c34\u5370\u56fe\u7247\u4e0d\u5b58\u5728\uff01&#8221;);<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; \/\/\u6c34\u5370\u4f4d\u7f6e<br \/> &nbsp; &nbsp; if($isWaterImage){\/\/\u56fe\u7247\u6c34\u5370<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $w = $water_w;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $h = $water_h;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $label = &#8220;\u56fe\u7247\u7684&#8221;;<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; if(($ground_w&lt;$w) || ($ground_h&lt;$h)){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; echo &#8220;\u9700\u8981\u52a0\u6c34\u5370\u7684\u56fe\u7247\u7684\u957f\u5ea6\u6216\u5bbd\u5ea6\u6bd4\u6c34\u5370&#8221;.$label.&#8221;\u8fd8\u5c0f\uff0c\u65e0\u6cd5\u751f\u6210\u6c34\u5370\uff01&#8221;;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; return;<span style=\"color:#ffffff\"> \/\/ www.ldhost.cn<\/span><br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; switch($waterPos){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 0:\/\/\u968f\u673a<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = rand(0,($ground_w &#8211; $w));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = rand(0,($ground_h &#8211; $h));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 1:\/\/1\u4e3a\u9876\u7aef\u5c45\u5de6<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = 0;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = 0;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 2:\/\/2\u4e3a\u9876\u7aef\u5c45\u4e2d<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = ($ground_w &#8211; $w) \/ 2;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = 0;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 3:\/\/3\u4e3a\u9876\u7aef\u5c45\u53f3<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = $ground_w &#8211; $w;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = 0;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 4:\/\/4\u4e3a\u4e2d\u90e8\u5c45\u5de6<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = 0;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = ($ground_h &#8211; $h) \/ 2;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 5:\/\/5\u4e3a\u4e2d\u90e8\u5c45\u4e2d<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = ($ground_w &#8211; $w) \/ 2;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = ($ground_h &#8211; $h) \/ 2;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 6:\/\/6\u4e3a\u4e2d\u90e8\u5c45\u53f3<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = $ground_w &#8211; $w;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = ($ground_h &#8211; $h) \/ 2;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 7:\/\/7\u4e3a\u5e95\u7aef\u5c45\u5de6<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = 0;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h &#8211; $h;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 8:\/\/8\u4e3a\u5e95\u7aef\u5c45\u4e2d<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = ($ground_w &#8211; $w) \/ 2;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h &#8211; $h;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 9:\/\/9\u4e3a\u5e95\u7aef\u5c45\u53f3<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = $ground_w &#8211; $w;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h &#8211; $h;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; if(!$isWaterImage){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = $ground_h &#8211; $h-20;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; default:\/\/\u968f\u673a<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posX = rand(0,($ground_w &#8211; $w));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $posY = rand(0,($ground_h &#8211; $h));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; break;<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; \/\/\u8bbe\u5b9a\u56fe\u50cf\u7684\u6df7\u8272\u6a21\u5f0f<br \/> &nbsp; &nbsp; imagealphablending($ground_im, true);<br \/> &nbsp; &nbsp; if($isWaterImage){\/\/\u56fe\u7247\u6c34\u5370<br \/> &nbsp; &nbsp; &nbsp; &nbsp; \/\/imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);\/\/\u62f7\u8d1d\u6c34\u5370\u5230\u76ee\u6807\u6587\u4ef6<br \/> &nbsp; &nbsp; &nbsp; &nbsp; \/\/\u751f\u6210\u6df7\u5408\u56fe\u50cf<br \/> &nbsp; &nbsp; &nbsp; &nbsp; imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h, $alpha);<br \/> &nbsp; &nbsp; } else {\/\/\u6587\u5b57\u6c34\u5370<br \/> &nbsp; &nbsp; &nbsp; &nbsp; if( !empty($textColor) &amp;&amp; (strlen($textColor)==7)){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $R = hexdec(substr($textColor,1,2));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $G = hexdec(substr($textColor,3,2));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $B = hexdec(substr($textColor,5));<br \/> &nbsp; &nbsp; &nbsp; &nbsp; } else {<br \/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; die(&#8220;\u6c34\u5370\u6587\u5b57\u989c\u8272\u683c\u5f0f\u4e0d\u6b63\u786e\uff01&#8221;);<br \/> &nbsp; &nbsp; &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; &nbsp; &nbsp; imagestring($ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; \/\/\u751f\u6210\u6c34\u5370\u540e\u7684\u56fe\u7247<br \/> &nbsp; &nbsp; @unlink($groundImage);<br \/> &nbsp; &nbsp; switch($ground_info[2]){\/\/\u53d6\u5f97\u80cc\u666f\u56fe\u7247\u7684\u683c\u5f0f<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 1:imagegif($ground_im,$groundImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 2:imagejpeg($ground_im,$groundImage,100);break;\/\/\u6ce8\u610f\u8fd9\u91cc\u7684100\uff0c\u7ecf\u6d4b\u8bd5\uff0c100\u662f\u56fe\u7247\u8d28\u91cf\u6700\u4f73\u7684\uff0c\u4f46\u6587\u4ef6\u5927\u5c0f\u4f1a\u589e\u52a0\u5f88\u591a\uff0c95\u7684\u65f6\u5019\u8d28\u91cf\u8fd8\u4e0d\u9519\uff0c\u5927\u5c0f\u548c\u539f\u6765\u7684\u5dee\u4e0d\u591a\u3002\u4f5c\u8005\u91c7\u752895\u7684\u503c\u3002<br \/> &nbsp; &nbsp; &nbsp; &nbsp; case 3:imagepng($ground_im,$groundImage);break;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; default:die($errorMsg);<br \/> &nbsp; &nbsp; }<br \/> &nbsp; &nbsp; \/\/\u91ca\u653e\u5185\u5b58<br \/> &nbsp; &nbsp; if(isset($water_info)) unset($water_info);<br \/> &nbsp; &nbsp; if(isset($water_im)) imagedestroy($water_im);<br \/> &nbsp; &nbsp; unset($ground_info);<br \/> &nbsp; &nbsp; imagedestroy($ground_im);<br \/> }<\/p>\n<p> \u7b2c\u4e8c\u6b65\uff0c\u627e\u5230$json = new Services_JSON();\uff08\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u6709\u4e24\u5904\uff0calert($msg)\u65b9\u6cd5\u91cc\u7684\u4e0d\u7528\u64cd\u4f5c\uff09\uff0c\u5728\u540e\u9762\u6dfb\u52a0\u5982\u4e0b\u4e00\u6bb5\u4ee3\u7801<\/p>\n<p> $water_mark = 1;\/\/1\u4e3a\u52a0\u6c34\u5370, \u5176\u5b83\u4e3a\u4e0d\u52a0<br \/> &nbsp; &nbsp; $water_pos = 9;\/\/\u6c34\u5370\u4f4d\u7f6e\uff0c10\u79cd\u72b6\u6001\u30100\u4e3a\u968f\u673a\uff0c1\u4e3a\u9876\u7aef\u5c45\u5de6\uff0c2\u4e3a\u9876\u7aef\u5c45\u4e2d\uff0c3\u4e3a\u9876\u7aef\u5c45\u53f3\uff1b4\u4e3a\u4e2d\u90e8\u5c45\u5de6\uff0c5\u4e3a\u4e2d\u90e8\u5c45\u4e2d\uff0c6\u4e3a\u4e2d\u90e8\u5c45\u53f3\uff1b7\u4e3a\u5e95\u7aef\u5c45\u5de6\uff0c8\u4e3a\u5e95\u7aef\u5c45\u4e2d\uff0c9\u4e3a\u5e95\u7aef\u5c45\u3011<br \/> &nbsp; &nbsp;$water_img = $_SERVER[&#8216;DOCUMENT_ROOT&#8217;].&#8217;\/images\/water.gif&#8217;;\/\/\u6c34\u5370\u56fe\u7247,\u9ed8\u8ba4\u586b\u5199\u7a7a,\u8bf7\u5c06\u56fe\u7247\u4e0a\u4f20\u81f3\u7f51\u7ad9\u6839\u76ee\u5f55\u7684images\u4e0b,\u4f8b: water.gif<br \/> &nbsp; &nbsp; $water_alpha = 50;\/\/\u6c34\u5370\u900f\u660e\u5ea6<br \/> &nbsp; &nbsp; $water_text = &#8221;;\/\/\u6c34\u5370\u5b57\u7b26\u4e32,\u9ed8\u8ba4\u586b\u5199\u7a7a;<br \/> &nbsp; &nbsp; \/\/$water_fontfile = $_SERVER[&#8216;DOCUMENT_ROOT&#8217;] .&#8217;\/upfiles\/fonts\/arial.ttf&#8217;;\/\/\u6587\u5b57\u6c34\u5370\u4f7f\u7528\u7684\u5b57\u4f53;<br \/> &nbsp; &nbsp; if($water_mark == 1){<br \/> &nbsp; &nbsp; &nbsp; &nbsp; imageWaterMark($file_path, $water_pos, $water_img, $water_alpha, $water_text);<br \/> &nbsp; &nbsp; }<\/p>\n<p> \u8fd9\u91cc\u53ea\u9700\u8981\u4e0a\u4f20\u4e00\u5f20\u6c34\u5370\u56fe\u7247\u5373\u53ef\u3002<\/p>\n<p> \u5b8c\u6210\u4e0a\u8ff0\u64cd\u4f5c\u540e\uff0c\u5728\u7528\u7f16\u8f91\u5668\u4e0a\u4f20\u56fe\u7247\u5c31\u53ef\u4ee5\u5b9e\u73b0\u4e0a\u56fe\u7684\u6548\u679c\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u6a21\u677f\u4ee5\u524d\u5728\u7f51\u7ad9\u4ecb\u7ecd\u8fc7ecsho&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-199383","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199383"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199383\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}