{"id":28995,"date":"2024-11-25T13:11:28","date_gmt":"2024-11-25T05:11:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28995\/"},"modified":"2024-11-25T13:11:28","modified_gmt":"2024-11-25T05:11:28","slug":"phpcms%e6%80%8e%e4%b9%88%e5%8e%8b%e7%bc%a9%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28995\/","title":{"rendered":"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247"},"content":{"rendered":"<blockquote><p>\n  phpcms\u538b\u7f29\u56fe\u7247\u7684\u65b9\u6cd5\uff1a\u9996\u5148\u627e\u5230\u5e76\u6253\u5f00\u201cextention.func.php\u201d\u6587\u4ef6\uff1b\u7136\u540e\u5728\u516c\u5171\u7c7b\u4e2d\u5199\u4e00\u4e2a\u81ea\u52a8\u538b\u7f29\u7684\u65b9\u6cd5\uff1b\u6700\u540e\u901a\u8fc7\u8bed\u53e5\u201c{compress ($rs[\u2018thumb\u2019])}\u201d\u5728html\u9875\u9762\u4e2d\u76f4\u63a5\u8c03\u7528\u5373\u53ef\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/5f1648c51378b828.jpg\" class=\"aligncenter\" title=\"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247\u63d2\u56fe\" alt=\"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247\u63d2\u56fe\" \/><\/p>\n<p><strong>\u56fe\u7247\u81ea\u52a8\u538b\u7f29\u529f\u80fd<\/strong><\/p>\n<p>\u5728\u516c\u5171\u7c7b\u4e2d\u5199\u4e00\u4e2a\u81ea\u52a8\u538b\u7f29\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>phpcmslibsunctionsextention.func.php\n**\n@param&nbsp;$imgName\n@return&nbsp;mixed|string\n$imgpath&nbsp;\u539f\u56fe\u5b58\u653e\u5730\u5740\n$thumbpath&nbsp;\u538b\u7f29\u540e\u56fe\u7247\u5b58\u653e\u8def\u5f84\n*\/\nfunction&nbsp;compress&nbsp;($imgName){\nimgPath=PHPCMSPATH.trim(imgPath&nbsp;=&nbsp;PHPCMS_PATH&nbsp;.&nbsp;trim(imgPath=PHPCMS&nbsp;\nP\n&nbsp;ATH.trim(imgName,&nbsp;\u2018\/\u2019);\n$Patharray&nbsp;=&nbsp;explode(\u2019\/\u2019,&nbsp;$imgName);\nfileName=end(fileName&nbsp;=&nbsp;end(fileName=end(Patharray);\n\/\/\u521b\u5efathumb\u6587\u4ef6\u5939,\u4fdd\u5b58\u538b\u7f29\u540e\u7684\u56fe\u7247\nheader(\u201cContent-type:text\/html;charset=utf-8\u201d);\n$path=\"\/uploadfile\/thumb\/\";\ndirPath=PHPCMSPATH.dirPath&nbsp;=&nbsp;PHPCMS_PATH.dirPath=PHPCMS&nbsp;\nP\n&nbsp;ATH.path;\nif(!is_dir(KaTeX&nbsp;parse&nbsp;error:&nbsp;Expected&nbsp;'}',&nbsp;got&nbsp;'EOF'&nbsp;at&nbsp;end&nbsp;of&nbsp;input:&nbsp;\u2026h)){&nbsp;mkdir(dirPath,0777,true);\n}\n$thumbPath&nbsp;=&nbsp;PHPCMS_PATH&nbsp;.&nbsp;\u2018uploadfile\/thumb\/\u2019&nbsp;.&nbsp;fileName;if(fileexists(fileName;if&nbsp;(file_exists(fileName;if(file&nbsp;\ne\n&nbsp;xists(thumbPath))&nbsp;{\nreturn&nbsp;APP_PATH&nbsp;.&nbsp;\u2018uploadfile\/thumb\/\u2019&nbsp;.&nbsp;$fileName;\n}else{\nsrc=imagecreatefromjpeg(src&nbsp;=&nbsp;imagecreatefromjpeg(src=imagecreatefromjpeg(imgPath);\nsrcw=imagesx(src_w&nbsp;=&nbsp;imagesx(src&nbsp;\nw\n&nbsp;=imagesx(src);\nsrch=imagesy(src_h&nbsp;=&nbsp;imagesy(src&nbsp;\nh\n&nbsp;=imagesy(src);\n\/\/\u8bbe\u7f6e\u7f29\u7565\u56fe\u5927\u5c0f\n$dst_w&nbsp;=&nbsp;$src_w1;\n$dst_h&nbsp;=&nbsp;$src_h1;\ndst=imagecreatetruecolor(dst&nbsp;=&nbsp;imagecreatetruecolor(dst=imagecreatetruecolor(dst_w,dsth);\/\/\u56fe\u7247\u91c7\u6837\u590d\u5236imagecopyresampled(dst_h);\/\/\u56fe\u7247\u91c7\u6837\u590d\u5236imagecopyresampled(dst&nbsp;\nh\n&nbsp;);\/\/\u56fe\u7247\u91c7\u6837\u590d\u5236imagecopyresampled(dst,src,0,0,0,0,src,0,0,0,0,src,0,0,0,0,dst_w,dsth,dst_h,dst&nbsp;\nh\n&nbsp;,src_w,srch);\/\/\u4fdd\u5b58\u7f29\u7565\u56feimagejpeg(src_h);\/\/\u4fdd\u5b58\u7f29\u7565\u56feimagejpeg(src&nbsp;\nh\n&nbsp;);\/\/\u4fdd\u5b58\u7f29\u7565\u56feimagejpeg(dst,thumbPath);\/\/\u9500\u6bc1\u8d44\u6e90imagedestroy(thumbPath);\/\/\u9500\u6bc1\u8d44\u6e90imagedestroy(thumbPath);\/\/\u9500\u6bc1\u8d44\u6e90imagedestroy(src);\nimagedestroy($dst);\nthumbPath=strreplace(PHPCMSPATH,\"\/\",thumbPath&nbsp;=&nbsp;str_replace(PHPCMS_PATH,\"\/\",thumbPath=str&nbsp;\nr\n&nbsp;eplace(PHPCMS&nbsp;\nP\n&nbsp;ATH,\"\/\",thumbPath);\nreturn&nbsp;$thumbPath;\n}\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/707\/561\/490\/1595295809724216.png\" class=\"aligncenter\" title=\"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247\u63d2\u56fe1\" alt=\"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247\u63d2\u56fe1\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/453\/739\/792\/1595295800215568.png\" class=\"aligncenter\" title=\"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247\u63d2\u56fe2\" alt=\"phpcms\u600e\u4e48\u538b\u7f29\u56fe\u7247\u63d2\u56fe2\" \/><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><span>\u70b9\u51fb\u4e0b\u8f7d<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u63a8\u8350\uff1a\u300a\u300b<\/p>\n<p>\u5728html\u9875\u9762\u4e2d\u76f4\u63a5\u8c03\u7528<\/p>\n<pre>{compress&nbsp;($rs[\u2018thumb\u2019])}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u538b\u7f29\u56fe\u7247\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>phpcms\u538b\u7f29\u56fe\u7247\u7684\u65b9\u6cd5\uff1a\u9996\u5148\u627e\u5230\u5e76\u6253\u5f00\u201cextention.func.php\u201d\u6587\u4ef6\uff1b\u7136\u540e\u5728\u516c\u5171\u7c7b\u4e2d\u5199\u4e00\u4e2a\u81ea\u52a8\u538b\u7f29\u7684\u65b9\u6cd5\uff1b\u6700\u540e\u901a\u8fc7\u8bed\u53e5\u201c{compress ($rs[\u2018thumb\u2019])}\u201d\u5728html\u9875\u9762\u4e2d\u76f4\u63a5\u8c03\u7528\u5373\u53ef\u3002 \u56fe\u7247\u81ea\u52a8\u538b\u7f29\u529f\u80fd \u5728\u516c\u5171\u7c7b\u4e2d\u5199\u4e00\u4e2a\u81ea\u52a8\u538b\u7f29\u7684\u65b9\u6cd5\uff1a phpcmslibsunctionsextention.func.php ** @param&nbsp;$imgName @return&nbsp;mixed|string $imgpath&nbsp;\u539f\u56fe\u5b58\u653e\u5730\u5740 $thumbpath&nbsp;\u538b\u7f29\u540e\u56fe\u7247\u5b58\u653e\u8def\u5f84 *\/ function&nbsp;compress&nbsp;($imgName){ imgPath=PHPCMSPATH.trim(imgPath&nbsp;=&nbsp;PHPCMS_PATH&nbsp;.&nbsp;trim(imgPath=PHPCMS&nbsp; P &nbsp;ATH.trim(imgName,&nbsp;\u2018\/\u2019); $Patharray&nbsp;=&nbsp;explode(\u2019\/\u2019,&nbsp;$imgName); fileName=end(fileName&nbsp;=&nbsp;end(fileName=end(Patharray); \/\/\u521b\u5efathumb\u6587\u4ef6\u5939,\u4fdd\u5b58\u538b\u7f29\u540e\u7684\u56fe\u7247 header(\u201cContent-type:text\/html;charset=utf-8\u201d); $path=&#8221;\/uploadfile\/thumb\/&#8221;; dirPath=PHPCMSPATH.dirPath&nbsp;=&nbsp;PHPCMS_PATH.dirPath=PHPCMS&nbsp; P &nbsp;ATH.path; if(!is_dir(KaTeX&nbsp;parse&nbsp;error:&nbsp;Expected&nbsp;&#8216;}&#8217;,&nbsp;got&nbsp;&#8216;EOF&#8217;&nbsp;at&nbsp;end&nbsp;of&nbsp;input:&nbsp;\u2026h)){&nbsp;mkdir(dirPath,0777,true); } $thumbPath&nbsp;=&nbsp;PHPCMS_PATH&nbsp;.&nbsp;\u2018uploadfile\/thumb\/\u2019&nbsp;.&nbsp;fileName;if(fileexists(fileName;if&nbsp;(file_exists(fileName;if(file&nbsp; e &nbsp;xists(thumbPath))&nbsp;{ return&nbsp;APP_PATH&nbsp;.&nbsp;\u2018uploadfile\/thumb\/\u2019&nbsp;.&nbsp;$fileName; }else{ src=imagecreatefromjpeg(src&nbsp;=&nbsp;imagecreatefromjpeg(src=imagecreatefromjpeg(imgPath); srcw=imagesx(src_w&nbsp;=&nbsp;imagesx(src&nbsp; w &nbsp;=imagesx(src); srch=imagesy(src_h&nbsp;=&nbsp;imagesy(src&nbsp; h &nbsp;=imagesy(src); \/\/\u8bbe\u7f6e\u7f29\u7565\u56fe\u5927\u5c0f $dst_w&nbsp;=&nbsp;$src_w1; $dst_h&nbsp;=&nbsp;$src_h1; dst=imagecreatetruecolor(dst&nbsp;=&nbsp;imagecreatetruecolor(dst=imagecreatetruecolor(dst_w,dsth);\/\/\u56fe\u7247\u91c7\u6837\u590d\u5236imagecopyresampled(dst_h);\/\/\u56fe\u7247\u91c7\u6837\u590d\u5236imagecopyresampled(dst&nbsp; h &nbsp;);\/\/\u56fe\u7247\u91c7\u6837\u590d\u5236imagecopyresampled(dst,src,0,0,0,0,src,0,0,0,0,src,0,0,0,0,dst_w,dsth,dst_h,dst&nbsp; h &nbsp;,src_w,srch);\/\/\u4fdd\u5b58\u7f29\u7565\u56feimagejpeg(src_h);\/\/\u4fdd\u5b58\u7f29\u7565\u56feimagejpeg(src&nbsp; h &nbsp;);\/\/\u4fdd\u5b58\u7f29\u7565\u56feimagejpeg(dst,thumbPath);\/\/\u9500\u6bc1\u8d44\u6e90imagedestroy(thumbPath);\/\/\u9500\u6bc1\u8d44\u6e90imagedestroy(thumbPath);\/\/\u9500\u6bc1\u8d44\u6e90imagedestroy(src); imagedestroy($dst); thumbPath=strreplace(PHPCMSPATH,&#8221;\/&#8221;,thumbPath&nbsp;=&nbsp;str_replace(PHPCMS_PATH,&#8221;\/&#8221;,thumbPath=str&nbsp; r &nbsp;eplace(PHPCMS&nbsp; P &nbsp;ATH,&#8221;\/&#8221;,thumbPath); return&nbsp;$thumbPath; } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-28995","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28995","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=28995"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28995\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}