{"id":2382,"date":"2012-12-24T14:04:51","date_gmt":"2012-12-24T06:04:51","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=2382"},"modified":"2012-12-24T14:06:05","modified_gmt":"2012-12-24T06:06:05","slug":"%e7%94%a8shell%e8%84%9a%e6%9c%ac%e6%89%b9%e9%87%8f%e5%8e%8b%e7%bc%a9%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/2382.html","title":{"rendered":"\u7528shell\u811a\u672c\u6279\u91cf\u538b\u7f29\u56fe\u7247"},"content":{"rendered":"<p><span style=\"font-size: small;\">\u73b0\u5728\u6211\u4eec\u7f51\u7ad9\u5bf9\u7528\u6237\u4e0a\u4f20\u7684\u56fe\u7247\u751f\u6210\u4e86\u4e09\u79cd\u89c4\u683c\u5927\u5c0f\u7684\u56fe\u7247\uff1a<\/span><\/p>\n<p><span style=\"font-size: small;\">\u4e00\u79cd\u5bbd\u6700\u5927590\uff0c\u9ad8\u6309\u6bd4\u4f8b\u9002\u5e94\uff0c\u5982\u3000.\/2012\/20121107\/4668\/201211071252339737_middle.jpg<\/span><br \/>\n<span style=\"font-size: small;\"> \u4e00\u79cd\u5bbd\u6700\u5927250\uff0c\u9ad8\u6309\u6bd4\u4f8b\u9002\u5e94\uff0c\u5982\u3000.\/2012\/20121107\/4668\/201211071252339737_small.jpg<\/span><br \/>\n<span style=\"font-size: small;\"> \u8fd8\u6709\u5c31\u662f\u539f\u56fe\uff0c\u5982\u3000.\/2012\/20121107\/4668\/201211071252339737.jpg\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u73b0\u5728\u56e0\u4e3a\u505a\u4e86\u624b\u673a\u7aef\u7684APP\uff0c\u8981\u6c42\u518d\u751f\u6210\u4e24\u79cd\u6bd4\u8f83\u5c0f\u89c4\u683c\u7684\u56fe\u7247\u7ed9\u624b\u673aAPP\u663e\u793a\u7528\u3002\u4e24\u79cd\u5982\u4e0b\u89c4\u683c\uff1a<\/span><\/p>\n<p><span style=\"font-size: small;\">\u5bbdx\u9ad8 = 200&#215;300\uff0c\u4e5f\u5c31\u662f\u5bbd\u6700\u5927\u4e0d\u8d85\u8fc7200\uff0c\u4e14\u9ad8\u6700\u5927\u4e0d\u8d85\u8fc7300\uff0c\u5728\u6b64\u6761\u4ef6\u4e0b\u6309\u6bd4\u4f8b\u7f29\u653e\u3002<\/span><br \/>\n<span style=\"font-size: small;\"> \u5bbdx\u9ad8 = 150&#215;150\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u5728\u7528php\u538b\u7f29\u7684\u65f6\u5019\uff0c\u9700\u8981\u8ba1\u7b97\u9ad8\u5bbd\u6bd4\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u770b\u5230\u5e95\u6309\u5bbd\u8fd8\u662f\u9ad8\u6765\u7b49\u6bd4\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u8fd9\u91cc\u9700\u8981\u89e3\u51b3\u7684\u95ee\u9898\u5c31\u662f\uff0c\u5982\u4f55\u5bf9\u4ee5\u524d\u7528\u6237\u4e0a\u4f20\u7684\u56fe\u7247\u8fdb\u884c\u5904\u7406\uff0c\u751f\u6210\u8fd9\u4e24\u79cd\u89c4\u683c\u7684\u56fe\u7247\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u6211\u5148\u662f\u5c1d\u8bd5\u7528php\uff0c\u5199php\u9875\u9762\uff0c\u7136\u540ecurl\u8c03\u7528\u3002\u8fd9\u6837\u5199\u4ee3\u7801\u5f88\u5feb\uff0c\u4f46\u662f\u5f53\u6211\u8dd1\u4e86\u4e00\u53f0\u673a\u5668\u540e\uff0c\u53d1\u73b0\u4e00\u4e9b\u95ee\u9898\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">1\u3001\u6709\u7684\u56fe\u7247\u5f88\u5927\uff0c\u538b\u7f29\u8017\u65f6\uff0c\u751a\u81f3\u8d85\u8fc7\u4e86php\u811a\u672c\u6267\u884c\u7684\u6700\u5927\u65f6\u95f4\uff0c\u5f53\u7136\u53ef\u4ee5\u8bbe\u7f6e\u52a0\u957fphp\u811a\u672c\u6700\u5927\u6267\u884c\u65f6\u95f4\uff0c\u4f46\u6539\u90a3\u4e48\u591a\u670d\u52a1\u5668\u7684\u914d\u7f6e\u4e0d\u662f\u5f88\u5408\u9002\u3002\u4ee5\u524d\u6211\u5c31\u662f\u51cf\u5c11\u4e00\u6b21php\u6267\u884c\u65f6\uff0c\u5904\u7406\u7684\u6570\u636e\u91cf\uff0c\u5982\u4e00\u6b21\u53ea\u5904\u740610\u5f20\u56fe\u7247\u3002\u4f46\u662f\u8fd9\u6837\u51e0\u5341\uff37\u56fe\u7247\uff0c\u4e00\u6b21\u5904\u740610\u5f20\uff0c\u90a3\u4e48\u8c03\u7528\u591a\u5c11\u6b21\u9875\u9762\u554a\uff01\u611f\u89c9\u4e0d\u723d\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">2\u3001\u6709\u65f6\u5019\uff0c\u56fe\u7247\u540e\u7f00\u662fJPG\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u5374\u662fPNG\u683c\u5f0f\uff08\u4e4b\u524d\u4e0a\u4f20\u56fe\u7247\u903b\u8f91\u90a3\u51faBUG\u9020\u6210\u7684\uff0c\u4e4b\u524d\u76f4\u63a5\u7528\u4e0a\u4f20\u6587\u4ef6\u7684\u540e\u7f00\u505a\u540e\u7f00\u4fdd\u5b58\u6587\u4ef6\uff0c\u6c57\uff09\u3002\u8fd8\u6709GIF\u56fe\u7247\u4e0d\u4f5c\u538b\u7f29\uff0c\u8fd8\u5f97\u5224\u65ad\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u8fd8\u6709php\u672c\u8eab\u7684\u7279\u70b9\uff0c\u4e0d\u9002\u5408\u505a\u8fd9\u6837\u5927\u578b\u3001\u975e\u5e38\u8017\u65f6\u7684\u5904\u7406\uff0c\u6240\u4ee5\u540e\u6765\u6211\u653e\u5f03\u7528php\u7ee7\u7eed\u5904\u7406\u3002\u8f6c\u5411\u5176\u5b83\u5b9e\u73b0\u601d\u8def\uff0c\u6211\u9996\u5148\u60f3\u5230\u4e86\u7528python\uff0cpython\u5b9e\u73b0\u8d77\u6765\u4e5f\u5feb\uff0c\u4f46\u6211\u4eec\u7684\u670d\u52a1\u5668\u4e0a\u6ca1\u88c5python\u8fd0\u884c\u73af\u5883\uff0c\u8fd8\u5f97\u88c5PIL\u5e93\uff0c\u6211\u81ea\u5df1\u53bb\u88c5\u4e5f\u5c31\u8fd8\u597d\uff0c\u4e0d\u5e9f\u4ec0\u4e48\u4e8b\uff0c\u4f46\u6743\u9650\u95ee\u9898\uff0c\u8fd8\u5f97\u53eb\u6211\u4eec\u7684\u8fd0\u7ef4\u88c5\uff0c\u4f30\u8ba1\u8fd0\u7ef4\u4e5f\u70e6\uff0c\u6211\u4e5f\u4e0d\u60f3\u9ebb\u70e6\u522b\u4eba\uff0c\u6240\u4ee5\u6700\u540e\u7528shell\u811a\u672c\u5b9e\u73b0\u4e86\uff0c\u800c\u4e14\u4ee3\u7801\u91cf\u66f4\u5c11\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u4e0b\u9762\u662f\u5b9e\u73b0\u7684shell\u4ee3\u7801resize_for_mobile.sh\uff1a<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n#encoding=utf-8\r\n\r\n#convert \u547d\u4ee4\r\nCONVERT_PATH='convert'\r\n\r\n# convert \u547d\u4ee4\u7684geometry\uff0c\u6309200x300\u6bd4\u4f8b\uff0c\u5176\u4e2d\u5bbd\u9ad8\u6700\u5927\u90fd\u4e0d\u8d85\u8fc7200\u548c300\r\n# http:\/\/www.imagemagick.org\/script\/command-line-processing.php#geometry\r\nSIZE_S1='200x300&gt;'\r\nSIZE_S2='150x150&gt;'\r\n\r\nLOG=''\r\nLOGFILE='resize_for_mobile.log'\r\n#find \u5339\u914d\u6587\u4ef6\u540d\uff0cyou need to specify .*\/ in the beginning because find matches the whole path\r\n#\u8fc7\u6ee4\u6389_small.jpg  _middle.jpg _s1.jpg _s2.jpg\u7b49\uff0c\u53ea\u53d6\u5168\u6570\u5b57+\u540e\u7f00\u7684\u6587\u4ef6\r\nfor imgfile in `find . -regextype sed -regex &quot;.*\/.*&#x5B;^s]&#x5B;0-9]\\..*&quot;`; do\r\n    LOG=&quot;${LOG} ${imgfile}&quot;\r\n    dir=`echo ${imgfile} | awk -F '.' '{print $2}'`\r\n    name=`echo ${imgfile} | awk -F '.' '{print $3}'`\r\n    s1name=.${dir}_s1.${name}\r\n    s2name=.${dir}_s2.${name}\r\n    if file ${imgfile} | grep &quot;GIF&quot;; then\r\n        LOG=&quot;${LOG} \u4e0d\u5904\u7406GIF\u6587\u4ef6&quot;\r\n    else\r\n        if &#x5B; -f ${s1name} ]; then\r\n            LOG=&quot;${LOG} ${s1name} \u5df2\u5b58\u5728 &quot;\r\n        else\r\n            ${CONVERT_PATH} ${imgfile} -quality 70 -resize ${SIZE_S1} ${s1name}\r\n        fi\r\n        if &#x5B; -f ${s2name} ]; then\r\n            LOG=&quot;${LOG} ${s2name} \u5df2\u5b58\u5728 &quot;\r\n        else\r\n            ${CONVERT_PATH} ${imgfile} -quality 70 -resize ${SIZE_S2} ${s2name}\r\n        fi\r\n    fi\r\n    echo -e &quot;${LOG}\\n&quot; &gt;&gt; ${LOGFILE}\r\ndone\r\n<\/pre>\n<p><span style=\"font-size: small;\">\u538b\u7f29\u56fe\u7247\u90e8\u5206\u4e3b\u8981\u7528\u5230\u4e86\u3000imagemagick\u3000\u7684\u3000convert\u3000\u547d\u4ee4\uff0c\u770b\u5176\u6587\u6863\u627e\u5230\u4e86\u6ee1\u8db3\u6211\u9700\u8981\u7684\u7528\u6cd5\u3002<\/span><br \/>\n<span style=\"font-size: small;\"> \u8fd8\u6709\u5c31\u662f\u67e5\u770b\u6587\u4ef6\u7684mime\u7c7b\u578b<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nfile -ib 20121124094332257.gif\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u5728\u6211\u4eec\u7f51\u7ad9\u5bf9\u7528\u6237\u4e0a\u4f20\u7684\u56fe\u7247\u751f\u6210\u4e86\u4e09\u79cd\u89c4\u683c\u5927\u5c0f\u7684\u56fe\u7247\uff1a \u4e00\u79cd\u5bbd\u6700\u5927590\uff0c\u9ad8\u6309\u6bd4\u4f8b\u9002\u5e94\uff0c\u5982\u3000.\/2012\/20 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2382","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=2382"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2382\/revisions"}],"predecessor-version":[{"id":2384,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2382\/revisions\/2384"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=2382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=2382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=2382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}