{"id":47419,"date":"2021-10-20T14:36:31","date_gmt":"2021-10-20T06:36:31","guid":{"rendered":"http:\/\/www.xyryd.com\/?p=47419"},"modified":"2021-10-20T14:38:28","modified_gmt":"2021-10-20T06:38:28","slug":"php-%e7%bc%a9%e5%9b%be%e5%88%a9%e5%99%a8%ef%bc%9atimthumb","status":"publish","type":"post","link":"http:\/\/www.xyryd.com\/47419.html","title":{"rendered":"PHP \u7f29\u56fe\u5229\u5668\uff1aTimThumb \u751f\u6210\u7f51\u9875\u622a\u56fe"},"content":{"rendered":"\n

TimThumb \u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u6d01\u65b9\u4fbf\u7528\u4e8e\u88c1\u56fe\u7684 PHP \u7a0b\u5e8f\uff0c\u53ea\u8981\u7ed9\u4ed6\u8bbe\u7f6e\u4e00\u4e9b\u53c2\u6570\uff0c\u5b83\u5c31\u53ef\u4ee5\u751f\u6210\u7f29\u7565\u56fe\u3002\u73b0\u5728\u5f88\u591a WordPress \u4e3b\u9898\u4e2d\uff0c\u90fd\u4f7f\u7528 TimThumb \u8fd9\u4e2a PHP \u7c7b\u5e93\u8fdb\u884c\u7f29\u7565\u56fe\u7684\u5904\u7406\u3002<\/p>\n\n\n\n

TimThumb \u7684\u4f7f\u7528<\/p>\n\n\n\n

TimThumb \u662f\u5bf9\u670d\u52a1\u5668\u6709\u8981\u6c42\u7684\uff0c\u9700\u8981\u670d\u52a1\u5668\u652f\u6301 GD \u5e93\uff0c\u73b0\u5728\u4e00\u822c\u7684\u4e3b\u673a\u90fd\u652f\u6301\uff0c\u7136\u540e\u5230 TimThumb \u5b98\u7f51\u4e0b\u8f7d\u811a\u672c\u5e76\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u5728\u548c TimThumb \u540c\u4e00\u4e2a\u76ee\u5f55\u4e0b\uff0c\u65b0\u5efa\u4e00\u4e2a cache \u6587\u4ef6\u5939\uff0c\u5e76\u4e14\u8bbe\u7f6e cache \u6587\u4ef6\u5939\u4e3a\u53ef\u5199\u3002<\/p>\n\n\n\n

TimThumb \u8fd9\u4e2a \u8fd9\u4e2a PHP \u88c1\u56fe\u811a\u672c\u4f7f\u7528\u8d77\u6765\u975e\u5e38\u7b80\u5355\uff0c\u4e0b\u9762\u5c31\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u56fe\u7247\u88c1\u526a\u6848\u4f8b\uff1a<\/p>\n\n\n\n

timthumb.php?src=my_image.jpg&h=150&w=150&zc=1\n\u5b83\u5c06\u56fe\u7247\u88c1\u526a\u6210\u5bbd\u4e3a150\uff0c\u9ad8\u4e3a150\u3002\u5982\u679c\u4f60\u4e0d\u60f3\u88c1\u526a\uff0c\u53ea\u662f\u538b\u7f29\u4e3a\uff0c\u5c06 zc \u53c2\u6570\u8bbe\u7f6e\u4e3a 0\u3002<\/code><\/pre>\n\n\n\n

\u9664\u4e86\u8fd9\u4e9b\u53c2\u6570\u4e4b\u5916\uff0cTimThumb \u8fd8\u6709\u5f88\u591a\u53c2\u6570\u53ef\u4ee5\u8ba9\u4f60\u8bbe\u7f6e\u3002<\/p>\n\n\n\n

\u53e6\u5916 TimThunb \u8fd8\u652f\u6301\u6ee4\u955c\uff0c\u4e4b\u5916\u5916\u90e8\u94fe\u63a5\u7b49\u3002\u603b\u4e4b\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u56fe\u7247\u7f29\u7565\u56fe\u5904\u7406\u5e93\u3002<\/p>\n\n\n\n

TimThumb \u7684\u7f3a\u70b9<\/p>\n\n\n\n

\u7531\u4e8e TimThumb \u662f\u901a\u8fc7\u53c2\u6570\u7684\u65b9\u5f0f\u6765\u8bbe\u7f6e\u7f29\u7565\u56fe\u7684\u5927\u5c0f\u548c\u5176\u4ed6\u4e00\u4e9b\u5c5e\u6027\uff0c\u6240\u4ee5\u5b83\u7684\u56fe\u7247\u6ca1\u6cd5\u8fdb\u884c\u4f2a\u9759\u6001\u5904\u7406\uff0c\u6240\u4ee5\u751f\u6210\u7684\u56fe\u7247\u4e5f\u65e0\u6cd5\u8fdb\u884c CDN \u52a0\u901f\u3002\u5e76\u4e14 TimThumb \u88c1\u56fe\u65f6\u5019\u662f\u9700\u8981\u6d88\u8017\u4e00\u5b9a\u670d\u52a1\u5668\u8d44\u6e90\u7684\u3002<\/p>\n\n\n\n

\u800c\u4e03\u725b\u4e91\u5b58\u50a8\u670d\u52a1\u652f\u6301\u56fe\u7247\u7f29\u7565\u3001\u88c1\u526a\u3001\u65cb\u8f6c\u3001\u8f6c\u5316\u7b49\u529f\u80fd\uff0c\u6240\u4ee5\u5982\u679c\u80fd\u591f\u57fa\u4e8e\u4e03\u725b\u7684\u4e91\u5b58\u50a8\u670d\u52a1\u5f00\u53d1\u4e00\u6b3e WordPress \u7f29\u7565\u56fe\u529f\u80fd\uff0c\u5c06\u662f\u975e\u5e38\u65b9\u4fbf\u5e76\u9ad8\u6548\u7684\u65b9\u5f0f\u3002\u5c3d\u8bf7\u671f\u5f85\u3002 ?<\/p>\n\n\n\n

\u8bbf\u95ee\u5730\u5740\u4e3a\uff1ahttp:\/\/localhost\/timthumb.php?src=http:\/\/localhost\/200.jpg&w=200&h=300&q=100&f=3,9|4,2&s=1&ct=1<\/code><\/pre>\n\n\n\n

\u53c2\u6570\u90fd\u662fget\u63d0\u4ea4\u7684\uff0c\u53ef\u9009\u53c2\u6570\u548c\u8bf4\u660e\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n

src<\/strong> : \u9700\u8981\u8fdb\u884c\u56fe\u7247\u7f29\u653e\u7684\u6e90\u56fe\u7247\u5730\u5740\uff0c\u6216\u8005\u662f\u9700\u8981\u8fdb\u884c\u622a\u56fe\u64cd\u4f5c\u7684\u7f51\u9875\u5730\u5740<\/p>\n\n\n\n

webshot<\/strong>: \u5982\u679c\u6b64\u503c\u4e3a\u771f\u5219\u8fdb\u884c\u622a\u56fe\u64cd\u4f5c<\/p>\n\n\n\n

w<\/strong> : \u751f\u6210\u56fe\u7247\u7684\u5bbd\u5ea6\uff0c\u5982\u679c\u5bbd\u5ea6\u6216\u9ad8\u5ea6\u53ea\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u503c\uff0c\u5219\u6839\u636e\u5176\u4e2d\u4e00\u4e2a\u503c\u8fdb\u884c\u7b49\u6bd4\u7f29\u653e<\/p>\n\n\n\n

h<\/strong> : \u751f\u6210\u56fe\u7247\u7684\u9ad8\u5ea6\uff0c\u5982\u679c\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u90fd\u6ca1\u6709\u6307\u5b9a\uff0c\u5219\u9ed8\u8ba4\u4e3a100*100<\/p>\n\n\n\n

zc<\/strong> : \u751f\u6210\u56fe\u7247\u7684\u7f29\u653e\u6a21\u5f0f\uff0c\u53ef\u9009\u503c0, 1, 2, 3, \u9ed8\u8ba4\u4e3a1\uff0c\u6bcf\u4e2a\u503c\u7684\u4e0d\u540c\u4e4b\u5904\u53ef\u770b\u4e0b\u9762\u6587\u4ef6\u7684\u7b2c100\u884c\u6ce8\u91ca<\/p>\n\n\n\n

q<\/strong> : \u751f\u6210\u56fe\u7247\u7684\u8d28\u91cf\uff0c\u9ed8\u8ba490<\/p>\n\n\n\n

a<\/strong> : \u8d85\u51fa\u90e8\u5206\u7684\u88c1\u526a\u4f4d\u7f6e\uff0c\u548c\u7f29\u653e\u6a21\u5f0f\u6709\u5173\uff0c\u53ef\u9009\u503ct, b, l, r, \u9ed8\u8ba4\u4e3a\u4ece\u9876\u90e8\u88c1\u526a<\/p>\n\n\n\n

f<\/strong> : \u9700\u8981\u5bf9\u751f\u6210\u540e\u7684\u56fe\u7247\u4f7f\u7528\u4e00\u4e9b\u8fc7\u6ee4\u5668\u7684\u8bdd\uff0c\u5219\u5728\u8fd9\u91cc\u4f20\u4e0d\u540c\u8fc7\u6ee4\u5668\u7684\u4ee3\u7801\u548c\u503c\uff0c\u5177\u4f53\u64cd\u4f5c\u65b9\u6cd5\u53ef\u89c1\u4e0b\u9762\u6587\u4ef6\u7684\u7b2c821\u884c\u6ce8\u89e3<\/p>\n\n\n\n

s<\/strong> : \u662f\u5426\u5bf9\u751f\u4ea7\u7684\u56fe\u7247\u8fdb\u884c\u9510\u5316\u5904\u7406<\/p>\n\n\n\n

cc<\/strong> : \u751f\u6210\u56fe\u7247\u7684\u80cc\u666f\u753b\u5e03\u989c\u8272<\/p>\n\n\n\n

ct<\/strong> : \u751f\u6210png\u56fe\u7247\u65f6\u80cc\u666f\u662f\u5426\u900f\u660e<\/p>\n\n\n\n

timthumb.php\u9010\u884c\u6ce8\u91ca\u529f\u80fd\u4f5c\u7528 \u4e2d\u6587\u7248<\/p>\n\n\n\n

<?php\n\/\/\u5b9a\u4e49\u7248\u672c\u4fe1\u606f\n<\/em><\/em>define ('VERSION', '2.8.10');\n\/\/\u5982\u679c\u6709\u914d\u7f6e\u6587\u4ef6\uff0c\u5219\u52a0\u8f7dtimthumb-config.php\uff0c\u6ca1\u6709\u7684\u8bdd\u4f7f\u7528\u4e0b\u9762\u7684\u503c\n<\/em><\/em>if( file_exists(dirname(__FILE__) . '\/timthumb-config.php')){\n  require_once('timthumb-config.php');\n}\n\/\/\u8c03\u8bd5\u65e5\u5fd7\u8bb0\u5f55\u5230web\u670d\u52a1\u5668\u65e5\u5fd7\u4e2d\n<\/em><\/em>if(! defined('DEBUG_ON') ){\n  define ('DEBUG_ON', false);\n}\n\/\/\u8c03\u8bd5\u7ea7\u522b\uff0c\u9ad8\u4e8e\u8fd9\u4e2a\u503c\u7684level\u90fd\u4e0d\u4f1a\u8bb0\u5f55\uff0c1\u6700\u4f4e\uff0c3\u6700\u9ad8\n<\/em><\/em>if(! defined('DEBUG_LEVEL') ){\n  define ('DEBUG_LEVEL', 1);\n}\n\/\/\u6700\u5927\u5360\u7528\u5185\u5b58\u9650\u523630M\n<\/em><\/em>if(! defined('MEMORY_LIMIT') ){\n  define ('MEMORY_LIMIT', '30M');\n}\n\/\/\u5173\u95ed\u4eff\u76d7\u94fe\n<\/em><\/em>if(! defined('BLOCK_EXTERNAL_LEECHERS') ){\n  define ('BLOCK_EXTERNAL_LEECHERS', false);\n} \t\t\t\t\t\n\/\/ \u5141\u8bb8\u4ece\u5916\u90e8\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>if(! defined('ALLOW_EXTERNAL') ){\n  define ('ALLOW_EXTERNAL', TRUE);\n}\n\/\/\u5141\u8bb8\u83b7\u53d6\u6240\u6709\u5916\u90e8\u7ad9\u70b9url\n<\/em><\/em>if(! defined('ALLOW_ALL_EXTERNAL_SITES') ){\n  define ('ALLOW_ALL_EXTERNAL_SITES', false);\n}\n\/\/\u542f\u7528\u6587\u4ef6\u7f13\u5b58\n<\/em><\/em>if(! defined('FILE_CACHE_ENABLED') ){\n  define ('FILE_CACHE_ENABLED', TRUE);\n}\n\/\/\u6587\u4ef6\u7f13\u5b58\u66f4\u65b0\u65f6\u95f4\uff0cs\n<\/em><\/em>if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')){\n  define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400);\n}\n\/\/\u6587\u4ef6\u7f13\u5b58\u751f\u5b58\u65f6\u95f4\uff0cs\uff0c\u8fc7\u4e86\u8fd9\u4e2a\u65f6\u95f4\u7684\u7f13\u5b58\u6587\u4ef6\u5c31\u4f1a\u88ab\u5220\u9664\n<\/em><\/em>if(! defined('FILE_CACHE_MAX_FILE_AGE') ){\n  define ('FILE_CACHE_MAX_FILE_AGE', 86400);\n}\n\/\/\u7f13\u5b58\u6587\u4ef6\u540e\u7f00\n<\/em><\/em>if(! defined('FILE_CACHE_SUFFIX') ){\n  define ('FILE_CACHE_SUFFIX', '.timthumb.txt');\n}\n\/\/\u7f13\u5b58\u6587\u4ef6\u524d\u7f00\n<\/em><\/em>if(! defined('FILE_CACHE_PREFIX') ){\n  define ('FILE_CACHE_PREFIX', 'timthumb');\n}\n\/\/\u7f13\u5b58\u6587\u4ef6\u76ee\u5f55\uff0c\u7559\u7a7a\u5219\u4f7f\u7528\u7cfb\u7edf\u4e34\u65f6\u76ee\u5f55\uff08\u63a8\u8350\uff09\n<\/em><\/em>if(! defined('FILE_CACHE_DIRECTORY') ){\n  define ('FILE_CACHE_DIRECTORY', '.\/cache');\n}\n\/\/<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6700\u5927\u5c3a\u5bf8\uff0c\u6b64\u811a\u672c\u6700\u5927\u80fd<strong>\u5904\u7406<\/strong>10485760\u5b57\u8282\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u4e5f\u5c31\u662f10M\n<\/em><\/em>if(! defined('MAX_FILE_SIZE') ){\n  define ('MAX_FILE_SIZE', 10485760);\n}  \n\/\/CURL\u7684\u8d85\u65f6\u65f6\u95f4\n<\/em><\/em>if(! defined('CURL_TIMEOUT') ){\n  define ('CURL_TIMEOUT', 20);\n}\n\/\/\u6e05\u7406\u9519\u8bef\u7f13\u5b58\u7684\u65f6\u95f4\n<\/em><\/em>if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ){\n  define ('WAIT_BETWEEN_FETCH_ERRORS', 3600);\n}\n\/\/\u6d4f\u89c8\u5668\u7f13\u5b58\u65f6\u95f4\n<\/em><\/em>if(! defined('BROWSER_CACHE_MAX_AGE') ){\n  define ('BROWSER_CACHE_MAX_AGE', 864000);\n}\n\/\/\u5173\u95ed\u6240\u6709\u6d4f\u89c8\u5668\u7f13\u5b58\n<\/em><\/em>if(! defined('BROWSER_CACHE_DISABLE') ){\n  define ('BROWSER_CACHE_DISABLE', false);\n}\n\/\/\u6700\u5927\u56fe\u50cf\u5bbd\u5ea6\n<\/em><\/em>if(! defined('MAX_WIDTH') ){\n  define ('MAX_WIDTH', 1500);\n}\n\/\/\u6700\u5927\u56fe\u50cf\u9ad8\u5ea6\n<\/em><\/em>if(! defined('MAX_HEIGHT') ){\n  define ('MAX_HEIGHT', 1500);\n}\n\/\/404\u9519\u8bef\u65f6\u663e\u793a\u7684\u63d0\u793a<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\uff0c\u8bbe\u7f6e\u6d4b\u503c\u5219\u4e0d\u4f1a\u663e\u793a\u5177\u4f53\u7684\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>if(! defined('NOT_FOUND_IMAGE') ){\n  define ('NOT_FOUND_IMAGE', '');\n}\n\/\/\u5176\u4ed6\u9519\u8bef\u65f6\u663e\u793a\u7684\u63d0\u793a<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\uff0c\u8bbe\u7f6e\u6d4b\u503c\u5219\u4e0d\u4f1a\u663e\u793a\u5177\u4f53\u7684\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>if(! defined('ERROR_IMAGE') ){\n  define ('ERROR_IMAGE', '');\n}\n\/\/PNG<strong><strong>\u56fe\u7247<\/strong><\/strong>\u80cc\u666f\u989c\u8272\uff0c\u4f7f\u7528false\u4ee3\u8868\u900f\u660e\n<\/em><\/em>if(! defined('PNG_IS_TRANSPARENT') ){\n  define ('PNG_IS_TRANSPARENT', FALSE);\n}\n\/\/\u9ed8\u8ba4<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8d28\u91cf\n<\/em><\/em>if(! defined('DEFAULT_Q') ){\n  define ('DEFAULT_Q', 90);\n}\n\/\/\u9ed8\u8ba4 \u7f29\u653e\/\u88c1\u526a \u6a21\u5f0f\uff0c0\uff1a\u6839\u636e\u4f20\u5165\u7684\u503c\u8fdb\u884c\u7f29\u653e\uff08\u4e0d\u88c1\u526a\uff09\uff0c 1\uff1a\u4ee5\u6700\u5408\u9002\u7684\u6bd4\u4f8b\u88c1\u526a\u548c\u8c03\u6574\u5927\u5c0f\uff08\u88c1\u526a\uff09\uff0c 2\uff1a\u6309\u6bd4\u4f8b\u8c03\u6574\u5927\u5c0f\uff0c\u5e76\u6dfb\u52a0\u8fb9\u6846\uff08\u88c1\u526a\uff09\uff0c2\uff1a\u6309\u6bd4\u4f8b\u8c03\u6574\u5927\u5c0f\uff0c\u4e0d\u6dfb\u52a0\u8fb9\u6846\uff08\u88c1\u526a\uff09\n<\/em><\/em>if(! defined('DEFAULT_ZC') ){\n  define ('DEFAULT_ZC', 1);\n}\n\/\/\u9ed8\u8ba4\u9700\u8981\u5bf9<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8fdb\u884c\u7684<strong>\u5904\u7406<\/strong>\u64cd\u4f5c\uff0c\u53ef\u9009\u503c\u548c\u53c2\u6570\u683c\u5f0f\u8bf7\u53c2\u770bprocessImageAndWriteToCache\u51fd\u6570\u4e2d\u7684$filters\u548c$imageFilters\u7684\u6ce8\u91ca\n<\/em><\/em>if(! defined('DEFAULT_F') ){\n  define ('DEFAULT_F', '');\n}\n\/\/\u662f\u5426\u5bf9<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8fdb\u884c\u9510\u5316\n<\/em><\/em>if(! defined('DEFAULT_S') ){\n  define ('DEFAULT_S', 0);\n}\n\/\/\u9ed8\u8ba4\u753b\u5e03\u989c\u8272\n<\/em><\/em>if(! defined('DEFAULT_CC') ){\n  define ('DEFAULT_CC', 'ffffff');\n}\n\/\/\u4ee5\u4e0b\u662f<strong><strong>\u56fe\u7247<\/strong><\/strong>\u538b\u7f29\u8bbe\u7f6e\uff0c\u524d\u63d0\u662f\u4f60\u7684\u4e3b\u673a\u4e2d\u6709optipng\u6216\u8005pngcrush\u8fd9\u4e24\u4e2a\u5de5\u5177\uff0c\u5426\u5219\u7684\u8bdd\u4e0d\u4f1a\u542f\u7528\u6b64\u529f\u80fd\n<\/em>\/\/\u6b64\u529f\u80fd\u53ea\u5bf9png<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6709\u6548\n<\/em><\/em>if(! defined('OPTIPNG_ENABLED') ){\n  define ('OPTIPNG_ENABLED', false);\n}  \nif(! defined('OPTIPNG_PATH') ){\n  define ('OPTIPNG_PATH', '\/usr\/bin\/optipng');\n} \/\/\u4f18\u5148\u4f7f\u7528optipng,\u56e0\u4e3a\u6709\u66f4\u597d\u7684\u538b\u7f29\u6bd4 \n<\/em><\/em>if(! defined('PNGCRUSH_ENABLED') ){\n  define ('PNGCRUSH_ENABLED', false);\n} \nif(! defined('PNGCRUSH_PATH') ){\n  define ('PNGCRUSH_PATH', '\/usr\/bin\/pngcrush');\n} \/\/optipng\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u4f7f\u7528pngcrush\n<\/em>\/\/<strong><strong>\u56fe\u7247<\/strong><\/strong>\u538b\u7f29\u8bbe\u7f6e\u7ed3\u675f\n<\/em><\/em>\n\n\/* \n<\/em> * * \u4ee5\u4e0b\u662f\u7f51\u7ad9\u622a\u56fe\u914d\u7f6e\n<\/em> * \u9996\u5148\uff0c\u7f51\u7ad9\u622a\u56fe\u9700\u8981root\u6743\u9650\n<\/em> * Ubuntu \u4e0a\u4f7f\u7528\u7f51\u7ad9\u622a\u56fe\u7684\u6b65\u9aa4\uff1a\n<\/em> *  1.\u7528\u8fd9\u4e2a\u547d\u4ee4\u5b89\u88c5Xvfb  sudo apt-get install subversion libqt4-webkit libqt4-dev g++ xvfb\n<\/em> *  2.\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u5e76\u4e0b\u8f7d\u4e0b\u9762\u7684\u6e90\u7801\n<\/em> *  3.\u7528\u8fd9\u4e2a\u547d\u4ee4\u4e0b\u8f7d\u6700\u65b0\u7684CutyCapt  svn co http:\/\/cutycapt.svn.sourceforge.net\/svnroot\/cutycapt\n<\/em> *  4.\u8fdb\u5165CutyCapt\u6587\u4ef6\u5939\n<\/em> *  5.\u7f16\u8bd1\u5e76\u5b89\u88c5CutyCapt\n<\/em> *  6.\u5c1d\u8bd5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a  xvfb-run --server-args=\"-screen 0, 1024x768x24\" CutyCapt --url=\"http:\/\/markmaunder.com\/\" --out=test.png\n<\/em> *  7.\u5982\u679c\u751f\u6210\u4e86\u4e00\u4e2a test.php\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u8bc1\u660e\u4e00\u5207\u6b63\u5e38\uff0c\u73b0\u5728\u901a\u8fc7\u6d4f\u89c8\u5668\u8bd5\u8bd5\uff0c\u8bbf\u95ee\u4e0b\u9762\u7684\u5730\u5740\uff1ahttp:\/\/yoursite.com\/path\/to\/timthumb.php?src=http:\/\/markmaunder.com\/&webshot=1\n<\/em> *\n<\/em> * \u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff1a\n<\/em> *  1.\u7b2c\u4e00\u6b21webshot\u52a0\u8f7d\u65f6\uff0c\u9700\u8981\u6570\u79d2\u949f\uff0c\u4e4b\u540e\u52a0\u8f7d\u5c31\u5f88\u5feb\u4e86\n<\/em> *\n<\/em> * \u9ad8\u7ea7\u7528\u6237\uff1a\n<\/em> *  1.\u5982\u679c\u60f3\u63d0\u901f\u5927\u7ea625%\uff0c\u5e76\u4e14\u4f60\u4e86\u89e3linux\uff0c\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a\n<\/em> *  nohup Xvfb :100 -ac -nolisten tcp -screen 0, 1024x768x24 > \/dev\/null 2>&1 &\n<\/em> *  \u5e76\u8bbe\u7f6e WEBSHOT_XVFB_RUNNING \u7684\u503c\u4e3atrue\n<\/em> *\n<\/em> * *\/<\/em>\n\/\/\u6d4b\u8bd5\u7684\u529f\u80fd\uff0c\u5982\u679c\u8bbe\u7f6e\u6b64\u503c\u4e3atrue, \u5e76\u5728\u67e5\u8be2\u5b57\u7b26\u4e32\u4e2d\u52a0\u4e0awebshot=1,\u4f1a\u8ba9\u811a\u672c\u8fd4\u56de\u6d4f\u89c8\u5668\u7684\u622a\u56fe\uff0c\u800c\u4e0d\u662f\u83b7\u53d6\u56fe\u50cf\n<\/em><\/em>if(! defined('WEBSHOT_ENABLED') ){\n  define ('WEBSHOT_ENABLED', false);\n}\n\/\/\u5b9a\u4e49CutyCapt\u5730\u5740\n<\/em><\/em>if(! defined('WEBSHOT_CUTYCAPT') ){\n  define ('WEBSHOT_CUTYCAPT', '\/usr\/local\/bin\/CutyCapt');\n}\n\/\/Xvfb\u5730\u5740\n<\/em><\/em>if(! defined('WEBSHOT_XVFB') ){\n  define ('WEBSHOT_XVFB', '\/usr\/bin\/xvfb-run');\n}\n\/\/\u622a\u56fe\u5c4f\u5e55\u5bbd\u5ea61024\n<\/em><\/em>if(! defined('WEBSHOT_SCREEN_X') ){\n  define ('WEBSHOT_SCREEN_X', '1024');\n}\n\/\/\u622a\u56fe\u5c4f\u5e55\u9ad8\u5ea6768\n<\/em><\/em>if(! defined('WEBSHOT_SCREEN_Y') ){\n  define ('WEBSHOT_SCREEN_Y', '768');\n}\n\/\/\u8272\u6df1\uff0c\u4f5c\u8005\u8bf4\u4ed6\u53ea\u6d4b\u8bd5\u8fc724\n<\/em><\/em>if(! defined('WEBSHOT_COLOR_DEPTH') ){\n  define ('WEBSHOT_COLOR_DEPTH', '24');\t\n}\n\/\/\u622a\u56fe\u683c\u5f0f\n<\/em><\/em>if(! defined('WEBSHOT_IMAGE_FORMAT') ){\n  define ('WEBSHOT_IMAGE_FORMAT', 'png');\n}\n\/\/\u622a\u56fe\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4ds\n<\/em><\/em>if(! defined('WEBSHOT_TIMEOUT') ){\n  define ('WEBSHOT_TIMEOUT', '20');\n}\n\/\/user_agent\u5934\n<\/em><\/em>if(! defined('WEBSHOT_USER_AGENT') ){\n  define ('WEBSHOT_USER_AGENT', \"Mozilla\/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.18) Gecko\/20110614 Firefox\/3.6.18\");\n}\n\/\/\u662f\u5426\u542f\u7528JS\n<\/em><\/em>if(! defined('WEBSHOT_JAVASCRIPT_ON') ){\n  define ('WEBSHOT_JAVASCRIPT_ON', true);\n}\n\/\/\u662f\u5426\u542f\u7528java\n<\/em><\/em>if(! defined('WEBSHOT_JAVA_ON') ){\n  define ('WEBSHOT_JAVA_ON', false);\n}\n\/\/\u5f00\u542fflash\u548c\u5176\u4ed6\u63d2\u4ef6\n<\/em><\/em>if(! defined('WEBSHOT_PLUGINS_ON') ){\n  define ('WEBSHOT_PLUGINS_ON', true);\n}\n\/\/\u4ee3\u7406\u670d\u52a1\u5668\n<\/em><\/em>if(! defined('WEBSHOT_PROXY') ){\n  define ('WEBSHOT_PROXY', '');\t\n}\n\/\/\u5982\u679c\u8fd0\u884c\u4e86XVFB,\u6b64\u9879\u8bbe\u4e3atrue\n<\/em><\/em>if(! defined('WEBSHOT_XVFB_RUNNING') ){\n  define ('WEBSHOT_XVFB_RUNNING', false);\n}\n\/\/ \u5982\u679c ALLOW_EXTERNAL \u7684\u503c\u4e3a\u771f \u5e76\u4e14 ALLOW_ALL_EXTERNAL_SITES \u7684\u503c\u4e3a\u5047\uff0c\u90a3\u4e48\u622a\u56fe\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u53ea\u80fd\u4ece\u4e0b\u9762\u8fd9\u4e9b\u6570\u7ec4\u4e2d\u7684\u57df\u548c\u5b50\u57df\u8fdb\u884c\n<\/em><\/em>if(! isset($ALLOWED_SITES)){\n  $ALLOWED_SITES = array (\n    'flickr.com',\n    'staticflickr.com',\n    'picasa.com',\n    'img.youtube.com',\n    'upload.wikimedia.org',\n    'photobucket.com',\n    'imgur.com',\n    'imageshack.us',\n    'tinypic.com',\n  );\n}\n\/*\u622a\u56fe\u914d\u7f6e\u7ed3\u675f*\/<\/em>\n\n\/\/ -------------------------------------------------------------\n<\/em>\/\/ -------------------------- \u914d\u7f6e\u7ed3\u675f ------------------------\n<\/em>\/\/ -------------------------------------------------------------\n<\/em><\/em>\ntimthumb::start();\n\nclass timthumb {\n\tprotected $src = \"\";  \/\/\u9700\u8981\u83b7\u53d6\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>url\n<\/em><\/em>\tprotected $is404 = false;  \/\/404\u9519\u8bef\u7801\n<\/em><\/em>\tprotected $docRoot = \"\";  \/\/\u670d\u52a1\u5668\u6587\u6863\u6839\u76ee\u5f55\n<\/em><\/em>\tprotected $lastURLError = false; \/\/\u4e0a\u4e00\u6b21\u8bf7\u6c42\u5916\u90e8url\u7684\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\tprotected $localImage = \"\"; \/\/\u5982\u679c\u8bf7\u6c42\u7684url\u662f\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u5219\u4e3a\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u5730\u5740\n<\/em><\/em>\tprotected $localImageMTime = 0;  \/\/\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u4fee\u6539\u65f6\u95f4\n<\/em><\/em>\tprotected $url = false;  \/\/\u7528parse_url\u89e3\u6790src\u540e\u7684\u6570\u7ec4\n<\/em><\/em>        protected $myHost = \"\";  \/\/\u672c\u673a\u57df\u540d\n<\/em><\/em>\tprotected $isURL = false;  \/\/\u662f\u5426\u4e3a\u5916\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\n<\/em><\/em>\tprotected $cachefile = ''; \/\/\u7f13\u5b58\u6587\u4ef6\u5730\u5740\n<\/em><\/em>\tprotected $errors = array();  \/\/\u9519\u8bef\u4fe1\u606f\u5217\u8868\n<\/em><\/em>\tprotected $toDeletes = array(); \/\/\u6790\u6784\u51fd\u6570\u4e2d\u9700\u8981\u5220\u9664\u7684\u8d44\u6e90\u5217\u8868\n<\/em><\/em>\tprotected $cacheDirectory = ''; \/\/\u7f13\u5b58\u5730\u5740\n<\/em><\/em>\tprotected $startTime = 0;  \/\/\u5f00\u59cb\u65f6\u95f4\n<\/em><\/em>\tprotected $lastBenchTime = 0; \/\/\u4e0a\u4e00\u6b21debug\u5b8c\u6210\u7684\u65f6\u95f4\n<\/em><\/em>\tprotected $cropTop = false;  \/\/\u662f\u5426\u542f\u7528\u88c1\u526a\n<\/em><\/em>\tprotected $salt = \"\";  \/\/\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\u548cinode\u8fde\u63a5\u7684\u5b57\u7b26\u4e32\u7684\u76d0\u503c\n<\/em><\/em>\tprotected $fileCacheVersion = 1; \/\/\u6587\u4ef6\u7f13\u5b58\u7248\u672c\uff0c\u5f53\u8fd9\u4e2a\u7c7b\u5347\u7ea7\u6216\u8005\u88ab\u66f4\u6539\u65f6\uff0c\u8fd9\u4e2a\u503c\u5e94\u8be5\u6539\u53d8\uff0c\u4ece\u800c\u91cd\u65b0\u751f\u6210\u7f13\u5b58\n<\/em><\/em>\tprotected $filePrependSecurityBlock = \"<?php die('Execution denied!'); \/\/\"; \/\/\u7f13\u5b58\u6587\u4ef6\u5b89\u5168\u5934\uff0c\u9632\u6b62\u76f4\u63a5\u8bbf\u95ee\n<\/em><\/em>\tprotected static $curlDataWritten = 0;  \/\/\u5c06curl\u83b7\u53d6\u5230\u7684\u6570\u636e\u5199\u5165\u7f13\u5b58\u6587\u4ef6\u7684\u957f\u5ea6\n<\/em><\/em>\tprotected static $curlFH = false;  \/\/curl\u8bf7\u6c42\u6210\u529f\u540e\u8981\u5c06\u83b7\u53d6\u5230\u7684\u6570\u636e\u5199\u5230\u6b64\u6587\u4ef6\u5185\n<\/em><\/em>\t\/*\u5916\u90e8\u8c03\u7528\u63a5\u53e3*\/<\/em>\n\tpublic static function start(){\n\t  \t\/\/\u5b9e\u4f8b\u5316\u6a21\u578b\n<\/em><\/em>\t  \t$tim = new timthumb();\n\t\t\/\/\u68c0\u67e5\u5b9e\u4f8b\u5316\u6a21\u578b\u65f6\u662f\u5426\u6709\u9519\u8bef\n<\/em><\/em>\t\t$tim->handleErrors();\n\t\t\/\/\u6b64\u51fd\u6570\u4e3a\u7a7a\uff0c\u7528\u505a\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u9a8c\u8bc1\n<\/em><\/em>\t\t$tim->securityChecks();\n\t\t\/\/\u5c1d\u8bd5\u8bfb\u53d6\u6d4f\u89c8\u5668\u7f13\u5b58\n<\/em><\/em>\t\tif($tim->tryBrowserCache()){\n\t\t  \t\/\/\u6210\u529f\u7684\u8bdd\u5c31\u8f93\u51fa\u7f13\u5b58\n<\/em><\/em>\t\t\texit(0);\n\t\t}\n\t\t\/\/\u68c0\u6d4b\u9519\u8bef\n<\/em><\/em>\t\t$tim->handleErrors();\n\t\t\/\/\u5982\u679c\u542f\u7528\u4e86\u6587\u4ef6\u7f13\u5b58\uff0c\u5e76\u4e14\u8bfb\u53d6\u670d\u52a1\u7aef\u7f13\u5b58\n<\/em><\/em>\t\tif(FILE_CACHE_ENABLED && $tim->tryServerCache()){\n\t\t  \t\/\/\u6210\u529f\u7684\u8bdd\u8f93\u51fa\u7f13\u5b58\n<\/em><\/em>\t\t\texit(0);\n\t\t}\n\t\t\/\/\u68c0\u6d4b\u8bfb\u53d6\u670d\u52a1\u7aef\u7f13\u5b58\u65f6\u7684\u9519\u8bef\n<\/em><\/em>\t\t$tim->handleErrors();\n\t\t\/\/\u751f\u6210\u548c<strong>\u5904\u7406<\/strong><strong><strong>\u56fe\u7247<\/strong><\/strong>\u4e3b\u51fd\u6570\n<\/em><\/em>\t\t$tim->run();\n\t\t\/\/\u68c0\u6d4b<strong><strong>\u56fe\u7247<\/strong><\/strong>\u751f\u6210\u548c<strong>\u5904\u7406<\/strong>\u65f6\u7684\u9519\u8bef\n<\/em><\/em>\t\t$tim->handleErrors();\n\t\t\/\/\u7a0b\u5e8f\u6267\u884c\u5b8c\u6bd5\u8fd0\u884c\u6790\u6784\u65b9\u6cd5\u5e76\u9000\u51fa\n<\/em><\/em>\t\texit(0);\n\t}\n\t\/*\u6784\u9020\u65b9\u6cd5\uff0c\u7528\u6765\u83b7\u53d6\u548c\u8bbe\u7f6e\u4e00\u4e9b\u57fa\u672c\u5c5e\u6027*\/<\/em>\n\tpublic function __construct(){\n\t  \t\/\/\u5c06\u5141\u8bb8\u7684\u57df\u8bbe\u4e3a\u5168\u5c40\u53d8\u91cf\n<\/em><\/em>\t  \tglobal $ALLOWED_SITES;\n\t\t\/\/\u8bb0\u5f55\u5f00\u59cb\u65f6\u95f4\n<\/em><\/em>\t\t$this->startTime = microtime(true);\n\t\t\/\/\u8bbe\u7f6e\u65f6\u533a\n<\/em><\/em>\t\tdate_default_timezone_set('UTC');\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8bf7\u6c42IP\u548c\u8bf7\u6c42URL\n<\/em><\/em>\t\t$this->debug(1, \"Starting new request from \" . $this->getIP() . \" to \" . $_SERVER['REQUEST_URI']);\n\t\t\/\/\u83b7\u53d6\u670d\u52a1\u5668\u6587\u6863\u6839\u76ee\u5f55\n<\/em><\/em>\t\t$this->calcDocRoot();\n\t\t\/\/\u83b7\u53d6\u6587\u4ef6\u7684\u4fee\u6539\u65f6\u95f4\u548cinode,inode\u53ea\u5728linux\u7cfb\u7edf\u4e0b\u6709\u6548\n<\/em><\/em>\t\t$this->salt = @filemtime(__FILE__) . '-' . @fileinode(__FILE__);\n\t\t\/\/\u8bb0\u5f55salt\u4fe1\u606f\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t$this->debug(3, \"Salt is: \" . $this->salt);\n\t\t\/\/\u5982\u679c\u5b9a\u4e49\u4e86\u7f13\u5b58\u6587\u4ef6\u5730\u5740\n<\/em><\/em>\t\tif(FILE_CACHE_DIRECTORY){\n\t\t  \t\/\/\u5982\u679c\u8fd9\u4e2a\u5730\u5740\u4e0d\u5b58\u5728\uff0c\u6216\u4e3a\u975e\u76ee\u5f55\n<\/em><\/em>\t\t  \tif(! is_dir(FILE_CACHE_DIRECTORY)){\n\t\t    \t\t\/\/\u5efa\u7acb\u8fd9\u4e2a\u76ee\u5f55\n<\/em><\/em>\t\t\t  \t@mkdir(FILE_CACHE_DIRECTORY);\n\t\t\t\t\/\/\u5982\u679c\u5efa\u7acb\u5931\u8d25\n<\/em><\/em>\t\t\t\tif(! is_dir(FILE_CACHE_DIRECTORY)){\n\t\t\t\t  \t\/\/\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\uff0c\u505c\u6b62\u6267\u884c\n<\/em><\/em>\t\t\t\t\t$this->error(\"Could not create the file cache directory.\");\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\/\/\u5c06\u7f13\u5b58\u5730\u5740\u5199\u5165\u6210\u5458\u5c5e\u6027\n<\/em><\/em>\t\t\t$this->cacheDirectory = FILE_CACHE_DIRECTORY;\n\t\t\t\/\/\u5728\u7f13\u5b58\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2aindex.html\u6587\u4ef6\uff0c\u9632\u6b62\u5217\u76ee\u5f55\n<\/em><\/em>\t\t\tif (!touch($this->cacheDirectory . '\/index.html')) {\n\t\t\t  \t\/\/\u5982\u679c\u51fa\u9519\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t$this->error(\"Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory.\");\n\t\t\t}\n\t\t\/\/\u5982\u679c\u6ca1\u5b9a\u4e49\u7f13\u5b58\u6587\u4ef6\u5730\u5740\uff0c\u5219\u7528\u7cfb\u7edf\u7684\u4e34\u65f6\u6587\u4ef6\u76ee\u5f55\u505a\u4e3a\u7f13\u5b58\u6587\u4ef6\u76ee\u5f55\n<\/em><\/em>\t\t} else {\n\t\t\t$this->cacheDirectory = sys_get_temp_dir();\n\t\t}\n\t\t\/\/\u8fdb\u884c\u7f13\u5b58\u68c0\u67e5\uff0c\u6e05\u9664\u8fc7\u671f\u7f13\u5b58\n<\/em><\/em>\t\t$this->cleanCache();\n\t\t\/\/\u8bb0\u5f55\u672c\u673a\u57df\u540d\n<\/em><\/em>\t\t$this->myHost = preg_replace('\/^www.\/i', '', $_SERVER['HTTP_HOST']);\n\t\t\/\/\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\uff0c\u6b64\u5730\u5740\u5e94\u8be5\u7531$_GET\u4e2d\u7684src\u53c2\u6570\u4f20\u9012\n<\/em><\/em>\t\t$this->src = $this->param('src');\n\t\t\/\/\u6b64\u6570\u7ec4\u662f\u89e3\u6790src\u540e\u7684\u7ed3\u679c\uff0c\u5305\u62ecscheme,host,port,user,pass,path,query,fragment\u5176\u4e2d\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\n<\/em><\/em>\t\t$this->url = parse_url($this->src);\n\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\u662f\u672c\u673a\u7684\uff0c\u5219\u5220\u9664<strong><strong>\u56fe\u7247<\/strong><\/strong>url\u4e2d\u672c\u673a\u7684\u57df\u540d\u90e8\u5206\n<\/em><\/em>\t\t$this->src = preg_replace('\/http?:\/\/(?:www.)?' . $this->myHost . '\/i', '', $this->src);\n\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\u7684\u957f\u5ea6\u5c0f\u4e8e3\uff0c\u5219\u662f\u65e0\u6548\u5730\u5740\n<\/em><\/em>\t\tif(strlen($this->src) <= 3){\n\t\t  \t\/\/\u6dfb\u52a0\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t$this->error(\"No image specified\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u5982\u679c\u5f00\u542f\u4e86\u9632\u76d7\u94fe\uff0c\u5e76\u4e14\u5b58\u5728\u6765\u6e90\u5730\u5740\uff0c\u4e5f\u5c31\u662fHTTP_REFERER\u5934\uff0c\u5e76\u4e14\u6765\u6e90\u5730\u5740\u4e0d\u662f\u672c\u673a\uff0c\u5219\u8fdb\u884c\u9632\u76d7\u94fe<strong>\u5904\u7406<\/strong>\n<\/em><\/em>\t\tif(BLOCK_EXTERNAL_LEECHERS && array_key_exists('HTTP_REFERER', $_SERVER) && (! preg_match('\/^http?:\/\/(?:www.)?' . $this->myHost . '(?:$|\/)\/i', $_SERVER['HTTP_REFERER']))){\n\t\t\t\/\/\u6b64base64\u7f16\u7801\u7684\u5185\u5bb9\u662f\u4e00\u5f20\u663e\u793a No Hotlinking\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t  \t$imgData = base64_decode(\"R0lGODlhUAAMAIAAAP8AAP\/\/\/yH5BAAHAP8ALAAAAABQAAwAAAJpjI+py+0Po5y0OgAMjjv01YUZnOGplhWXfNa6JCLnWkXplrcBmW+spbwvaVr\/cDyg7IoFC2KbYVC2NQ5MQ4ZNao9Ynzjl9ScNYpnebnDULB3RP6JuPuaGfuuV4fumf8PuvqFyhYtjdoeFgAADs=\");\n\t\t\t\/\/\u663e\u793a\u5185\u5bb9\u4e3agif<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t\theader('Content-Type: image\/gif');\n\t\t\t\/\/\u5185\u5bb9\u957f\u5ea6\n<\/em><\/em>\t\t\theader('Content-Length: ' . sizeof($imgData));\n\t\t\t\/\/\u65e0<strong>\u7f51\u9875<\/strong>\u7f13\u5b58\n<\/em><\/em>\t\t\theader('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');\n\t\t\t\/\/\u517c\u5bb9http1.0\u548chttp\n<\/em><\/em>\t\t\theader(\"Pragma: no-cache\");\n\t\t\t\/\/\u5185\u5bb9\u7acb\u5373\u8fc7\u671f\n<\/em><\/em>\t\t\theader('Expires: ' . gmdate ('D, d M Y H:i:s', time()));\n\t\t\t\/\/\u8f93\u51fa<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t\techo $imgData;\n\t\t\treturn false;\n\t\t\t\/\/\u9000\u51fa\u811a\u672c\n<\/em><\/em>\t\t\texit(0);\n\t\t}\n\t\t\/\/\u5982\u679c\u6b64\u65f6\u7684src\u5c5e\u6027\u5305\u542bhttp\u7b49\u5b57\u7b26\uff0c\u8bf4\u660e\u662f\u5916\u90e8\u94fe\u63a5\n<\/em><\/em>\t\tif(preg_match('\/^http?:\/\/[^\/]+\/i', $this->src)){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bf4\u660e\u8fd9\u4e2a\u94fe\u63a5\u662f\u5916\u90e8\u7684\uff0c\u7ea7\u522b2\n<\/em><\/em>\t\t  \t$this->debug(2, \"Is a request for an external URL: \" . $this->src);\n\t\t\t\/\/\u5c06isURL\u8bbe\u4e3atrue\uff0c\u8bf4\u660e\u662f\u5916\u90e8url\n<\/em><\/em>\t\t\t$this->isURL = true;\n\t\t\/\/\u5982\u679c\u4e0d\u5305\u542b\u7684\u8bdd\uff0c\u8bf4\u660e\u662f\u5185\u90e8\u94fe\u63a5\n<\/em><\/em>\t\t} else {\n\t\t\t$this->debug(2, \"Is a request for an internal file: \" . $this->src);\n\t\t}\n\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684src\u662f\u5916\u90e8\u7f51\u7ad9\uff0c\u5e76\u4e14\u914d\u7f6e\u6587\u4ef6\u4e0d\u5141\u8bb8\u4ece\u5916\u90e8\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u5219\u9000\u51fa\n<\/em><\/em>\t\tif($this->isURL && (! ALLOW_EXTERNAL)){\n\t\t\t$this->error(\"You are not allowed to fetch images from an external website.\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u5982\u679c\u5141\u8bb8\u4ece\u5916\u90e8\u7f51\u7ad9\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\tif($this->isURL){\n\t\t  \t\/\/\u5e76\u4e14\u914d\u7f6e\u6587\u4ef6\u5141\u8bb8\u4ece\u6240\u6709\u7684\u5916\u90e8\u7f51\u7ad9\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t  \tif(ALLOW_ALL_EXTERNAL_SITES){\n\t\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u5141\u8bb8\u4ece\u5916\u90e8\u7f51\u7ad9\u53d6\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u7ea7\u522b2\n<\/em><\/em>\t\t\t  \t$this->debug(2, \"Fetching from all external sites is enabled.\");\n\t\t\t\/\/\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u4e0d\u5141\u8bb8\u4ece\u6240\u6709\u7684\u5916\u90e8\u7f51\u7ad9\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t\t} else {\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u53ea\u80fd\u4ece\u6307\u5b9a\u7684\u5916\u90e8\u7f51\u7ad9\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u7ea7\u522b2\n<\/em><\/em>\t\t\t  \t$this->debug(2, \"Fetching only from selected external sites is enabled.\");\n\t\t\t\t\/\/\u6b64\u4e3a\u9a8c\u8bc1\u4f4d\uff0c\u9ed8\u8ba4\u4e3afalse\n<\/em><\/em>\t\t\t\t$allowed = false;\n\t\t\t\t\/\/\u904d\u5386\u914d\u7f6e\u6587\u4ef6\u4e2d\u5141\u8bb8\u7ad9\u70b9\u7684\u5217\u8868\n<\/em><\/em>\t\t\t\tforeach($ALLOWED_SITES as $site){\n\t\t\t\t  \t\/\/\u8fd9\u91cc\u5bf9<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684url\u8ddf\u5141\u8bb8\u8bbf\u95ee\u7ad9\u70b9\u7684\u5217\u8868\u8fdb\u884c\u9a8c\u8bc1\uff0c\u524d\u9762\u7684\u6761\u4ef6\u5bf9\u5e94\u7684\u662f\u6709\u4e3b\u673a\u540d\u7684\uff0c\u540e\u9762\u7684\u5185\u5bb9\u5bf9\u5e94\u7684\u662f\u6ca1\u6709\u4e3b\u673a\u540d\u7684\uff0c\u5199\u7684\u5f88\u7cbe\u5de7\n<\/em><\/em>\t\t\t\t  \tif ((strtolower(substr($this->url['host'],-strlen($site)-1)) === strtolower(\".$site\")) || (strtolower($this->url['host'])===strtolower($site))) {\n\t\t\t\t\t\t\/\/\u901a\u8fc7\u9a8c\u8bc1\u5219\u5199\u4e00\u6761\u65e5\u5fd7\uff0c\u9a8c\u8bc1\u6210\u529f\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t\t  \t$this->debug(3, \"URL hostname {$this->url['host']} matches $site so allowing.\");\n\t\t\t\t\t\t\/\/\u9a8c\u8bc1\u4f4d\u4e3atrue\n<\/em><\/em>\t\t\t\t\t\t$allowed = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\/\/\u5982\u679c\u6ca1\u901a\u8fc7\u9a8c\u8bc1\uff0c \u5199\u9519\u8bef\u4fe1\u606f\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\t\tif(! $allowed){\n\t\t\t\t\treturn $this->error(\"You may not fetch images from that site. To enable this site in timthumb, you can either add it to $ALLOWED_SITES and set ALLOW_EXTERNAL=true. Or you can set ALLOW_ALL_EXTERNAL_SITES=true, depending on your security needs.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\/\/\u7f13\u5b58\u6587\u4ef6\u7684\u524d\u7f00\uff0c\u5982\u679c\u662f\u5185\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u7528_int_\uff0c\u5916\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7528_ext_\n<\/em><\/em>\t\t$cachePrefix = ($this->isURL ? '_ext_' : '_int_');\n\t\t\/\/\u5982\u679c\u662f\u5916\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\n<\/em><\/em>\t\tif($this->isURL){\n\t\t  \t\/\/\u5f97\u5230GET\u5b57\u7b26\u4e32\u7684\u6570\u7ec4\n<\/em><\/em>\t\t  \t$arr = explode('&', $_SERVER ['QUERY_STRING']);\n\t\t\t\/\/\u6309\u5b57\u6bcd\u987a\u5e8f\u5bf9\u6570\u7ec4\u5143\u7d20\u6392\u5e8f\n<\/em><\/em>\t\t\tasort($arr);\n\t\t\t\/\/\u751f\u6210\u7f13\u5b58\u6587\u4ef6\u5730\u5740  \u7f13\u5b58\u76ee\u5f55 + \/ + \u7f13\u5b58\u524d\u7f00 + $cachePrefix + \u552f\u4e00\u6563\u5217\u503c  + \u7f13\u5b58\u540e\u7f00\n<\/em><\/em>\t\t\t$this->cachefile = $this->cacheDirectory . '\/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . implode('', $arr) . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;\n\t\t\/\/\u5982\u679c\u662f\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t} else {\n\t\t  \t\/\/\u83b7\u53d6\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\n<\/em><\/em>\t\t  \t$this->localImage = $this->getLocalImagePath($this->src);\n\t\t\t\/\/\u5982\u679c\u83b7\u53d6\u4e0d\u5230\u5730\u5740\n<\/em><\/em>\t\t\tif(! $this->localImage){\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u6ca1\u6709\u627e\u5230\u6b64\u6587\u4ef6\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\t  \t$this->debug(1, \"Could not find the local image: {$this->localImage}\");\n\t\t\t\t\/\/\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t$this->error(\"Could not find the internal image you specified.\");\n\t\t\t\t\/\/\u8bbe\u7f6e404\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t$this->set404();\n\t\t\t\t\/\/\u7ec8\u6b62\u6267\u884c\u7a0b\u5e8f\n<\/em><\/em>\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4fe1\u606f\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\t$this->debug(1, \"Local image path is {$this->localImage}\");\n\t\t\t\/\/\u83b7\u53d6\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\n<\/em><\/em>\t\t\t$this->localImageMTime = @filemtime($this->localImage);\n\t\t\t\/\/\u751f\u6210\u7f13\u5b58\u6587\u4ef6\u5730\u5740,  \u7f13\u5b58\u76ee\u5f55 + \/ + \u7f13\u5b58\u524d\u7f00 + $cachePrefix + \u552f\u4e00\u6563\u5217\u503c + \u7f13\u5b58\u540e\u7f00\n<\/em><\/em>\t\t\t$this->cachefile = $this->cacheDirectory . '\/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . $this->localImageMTime . $_SERVER ['QUERY_STRING'] . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;\n\t\t}\n\t\t\/\/\u8bb0\u5f55\u7f13\u5b58\u6587\u4ef6\u5730\u5740\n<\/em><\/em>\t\t$this->debug(2, \"Cache file is: \" . $this->cachefile);\n\t\t\/\/\u6784\u9020\u51fd\u6570\u5b8c\u6210\n<\/em><\/em>\t\treturn true;\n\t}\n\t\/*\u6790\u6784\u65b9\u6cd5\uff0c\u5220\u9664toDeletes\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6587\u4ef6*\/<\/em>\n\tpublic function __destruct(){\n\t\tforeach($this->toDeletes as $del){\n\t\t\t$this->debug(2, \"Deleting temp file $del\");\n\t\t\t@unlink($del);\n\t\t}\n\t}\n\t\/*\u4e3b\u51fd\u6570\uff0c\u901a\u8fc7\u4e0d\u540c\u53c2\u6570\u8c03\u7528\u4e0d\u540c\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong><strong>\u5904\u7406<\/strong>\u51fd\u6570*\/<\/em>\n\tpublic function run(){\n\t  \t\/\/\u5982\u679c\u662f\u5916\u90e8\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u94fe\u63a5\n<\/em><\/em>\t  \tif($this->isURL){\n\t\t\t\/\/\u4f46\u662f\u914d\u7f6e\u6587\u4ef6\u4e0d\u5141\u8bb8\u4ece\u5916\u90e8\u83b7\u53d6\u94fe\u63a5\n<\/em><\/em>\t\t  \tif(! ALLOW_EXTERNAL){\n\t\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bf4\u660e\u914d\u7f6e\u6587\u4ef6\u7981\u6b62\u8bbf\u95ee\u5916\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\t  \t$this->debug(1, \"Got a request for an external image but ALLOW_EXTERNAL is disabled so returning error msg.\");\n\t\t\t\t\/\/\u5199\u9519\u8bef\u8bb0\u5f55\n<\/em><\/em>\t\t\t\t$this->error(\"You are not allowed to fetch images from an external website.\");\n\t\t\t\t\/\/\u9000\u51fa\u6267\u884c\n<\/em><\/em>\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u914d\u7f6e\u6587\u4ef6\u5141\u8bb8\u4ece\u5916\u90e8\u83b7\u53d6\u94fe\u63a5\uff0c\u5219\u5199\u65e5\u5fd7\uff0c\u63a5\u7740\u8fd0\u884c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t$this->debug(3, \"Got request for external image. Starting serveExternalImage.\");\n\t\t\t\/\/\u5982\u679cget\u4e86webshot\u53c2\u6570\u5e76\u4e14\u4e3a\u771f\uff0c\u5219\u8fdb\u884c\u622a\u56fe\u64cd\u4f5c\n<\/em><\/em>\t\t\tif($this->param('webshot')){\n\t\t\t  \t\/\/\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u5141\u8bb8\u622a\u56fe\n<\/em><\/em>\t\t\t  \tif(WEBSHOT_ENABLED){\n\t\t\t    \t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bf4\u660e\u8981\u8fdb\u884c\u622a\u56fe\u64cd\u4f5c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t  \t$this->debug(3, \"webshot param is set, so we're going to take a webshot.\");\n\t\t\t\t\t\/\/\u622a\u56fe\u64cd\u4f5c\n<\/em><\/em>\t\t\t\t\t$this->serveWebshot();\n\t\t\t\t\/\/\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u4e0d\u5141\u8bb8\u622a\u56fe\n<\/em><\/em>\t\t\t\t} else {\n\t\t\t\t  \t\/\/\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\t\t\t$this->error(\"You added the webshot parameter but webshots are disabled on this server. You need to set WEBSHOT_ENABLED == true to enable webshots.\");\n\t\t\t\t}\n\t\t\t\/\/\u5982\u679c\u4e0d\u5b58\u5728sebshot\u53c2\u6570\u6216\u4e3a\u5047\n<\/em><\/em>\t\t\t} else {\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u4e0d\u8fdb\u884c\u622a\u56fe\u64cd\u4f5c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t  \t$this->debug(3, \"webshot is NOT set so we're going to try to fetch a regular image.\");\n\t\t\t\t\/\/\u4ece\u5916\u90e8URL\u83b7\u5f97<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5e76<strong>\u5904\u7406<\/strong>\n<\/em><\/em>\t\t\t\t$this->serveExternalImage();\n\n\t\t\t}\n\t\t\/\/\u5426\u5219\u7684\u8bdd\u5c31\u662f\u5185\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t} else {\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u662f\u5185\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t  \t$this->debug(3, \"Got request for internal image. Starting serveInternalImage()\");\n\t\t\t\/\/\u83b7\u5f97\u5185\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5e76<strong>\u5904\u7406<\/strong>\n<\/em><\/em>\t\t\t$this->serveInternalImage();\n\t\t}\n\t\t\/\/\u7a0b\u5e8f\u6267\u884c\u5b8c\u6bd5\n<\/em><\/em>\t\treturn true;\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765<strong>\u5904\u7406<\/strong>\u9519\u8bef*\/<\/em>\n\tprotected function handleErrors(){\n\t  \t\/\/\u5982\u679c\u9519\u8bef\u5217\u8868\u4e2d\u6709\u5185\u5bb9\n<\/em><\/em>\t  \tif($this->haveErrors()){\n\t\t\t\/\/\u9996\u5148\u68c0\u6d4b404\u9519\u8bef\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86404<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\u5e76\u4e14\u7684\u786e\u6709404\u9519\u8bef\n<\/em><\/em>\t\t  \tif(NOT_FOUND_IMAGE && $this->is404()){\n\t\t\t\t\/\/\u90a3\u4e48\u8f93\u51fa\u9519\u8bef<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u5e76\u9000\u51fa\u811a\u672c\n<\/em><\/em>\t\t\t\tif($this->serveImg(NOT_FOUND_IMAGE)){\n\t\t\t\t  \texit(0);\n\t\t\t\t\/\/\u8f93\u51fa\u5931\u8d25\u7684\u8bdd\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t} else {\n\t\t\t\t\t$this->error(\"Additionally, the 404 image that is configured could not be found or there was an error serving it.\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u6ca1\u6709404\u9519\u8bef\uff0c\u5e76\u4e14\u5b9a\u4e49\u4e86\u9519\u8bef<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u90a3\u4e48\u8f93\u51fa\u6b64<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t\tif(ERROR_IMAGE){\n\t\t\t  \t\/\/\u8f93\u51fa\u5176\u4ed6\u9519\u8bef\u63d0\u793a<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u5e76\u9000\u51fa\u811a\u672c\n<\/em><\/em>\t\t\t\tif($this->serveImg(ERROR_IMAGE)){\n\t\t\t\t  \texit(0);\n\t\t\t\t\/\/\u8f93\u51fa\u5931\u8d25\u7684\u8bdd\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t} else {\n\t\t\t\t\t$this->error(\"Additionally, the error image that is configured could not be found or there was an error serving it.\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u4e0a\u9762\u4e24\u4e2a\u5e38\u91cf\u90fd\u6ca1\u5b9a\u4e49\uff0c\u5219\u6839\u636e\u6a21\u677f\u8f93\u51fa\u8be6\u7ec6\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t$this->serveErrors(); \n\t\t\texit(0); \n\t\t}\n\t\t\/\/\u6ca1\u6709\u9519\u8bef\u7684\u8bdd\u8fd4\u56de\u5047\n<\/em><\/em>\t\treturn false;\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8bfb\u53d6\u6d4f\u89c8\u5668\u7f13\u5b58\u6587\u4ef6\uff0c\u524d\u63d0\u662f\u6d4f\u89c8\u5668\u7f13\u5b58\u7684\u6587\u4ef6\u6709\u6548\uff0c\u5177\u4f53\u7684\u5b9e\u73b0\u8bf7\u770b\u51fd\u6570\u5185\u90e8*\/<\/em>\n\tprotected function tryBrowserCache(){\n\t  \t\/\/\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u5173\u95ed\u4e86\u6240\u6709\u6d4f\u89c8\u5668\u7f13\u5b58\uff0c\u5219\u5199\u65e5\u5fd7\uff0c\u5e76\u8fd4\u56de\u5047\n<\/em><\/em>\t  \tif(BROWSER_CACHE_DISABLE){ \n\t\t  \t$this->debug(3, \"Browser caching is disabled\"); return false; \n\t\t}\n\t\t\/\/\u5982\u679c\u6d4f\u89c8\u5668\u8bb0\u5f55\u4e86\u9875\u9762\u4e0a\u6b21\u4fee\u6539\u7684\u65f6\u95f4\n<\/em><\/em>\t\tif(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t  \t$this->debug(3, \"Got a conditional get\");\n\t\t\t\/\/\u7f13\u5b58\u6587\u4ef6\u6700\u540e\u4fee\u6539\u65f6\u95f4\n<\/em><\/em>\t\t\t$mtime = false;\n\t\t\t\/\/\u5982\u679c\u7f13\u5b58\u5730\u5740\u65e0\u6548\n<\/em><\/em>\t\t\tif(! is_file($this->cachefile)){\n\t\t\t\t\/\/\u8bf4\u660e\u6ca1\u6709\u7f13\u5b58\uff0c\u8fd4\u56de\u5047\n<\/em><\/em>\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u5b58\u5728\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4fee\u6539\u65f6\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u6240\u8bf7\u6c42\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u662f\u672c\u673a\u7684\n<\/em><\/em>\t\t\tif($this->localImageMTime){\n\t\t\t  \t\/\/\u7f13\u5b58\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\u8bbe\u7f6e\u4e3a\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4fee\u6539\u65f6\u95f4\n<\/em><\/em>\t\t\t  \t$mtime = $this->localImageMTime;\n\t\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u5b9e\u9645\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t$this->debug(3, \"Local real file's modification time is $mtime\");\n\t\t\t\/\/\u5982\u679c\u8bf7\u6c42\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4e0d\u662f\u672c\u5730\u7684\n<\/em><\/em>\t\t\t} else if(is_file($this->cachefile)){\n\t\t\t  \t\/\/\u83b7\u53d6\u7f13\u5b58\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\n<\/em><\/em>\t\t\t  \t$mtime = @filemtime($this->cachefile);\n\t\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u7f13\u5b58\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t$this->debug(3, \"Cached file's modification time is $mtime\");\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u6ca1\u6709\u83b7\u53d6\u5230\u7f13\u5b58\u6587\u4ef6\u6700\u540e\u4fee\u6539\u65f6\u95f4\uff0c\u8bf4\u660e\u6ca1\u6709\u7f13\u5b58\uff0c\u9000\u51fa\n<\/em><\/em>\t\t\tif(! $mtime){ return false; }\n\t\t\t\/\/\u5c06\u6d4f\u89c8\u5668\u4e2d\u5b58\u50a8\u7684\u4e0a\u6b21\u4fee\u6539\u65f6\u95f4\u8f6c\u4e3a\u65f6\u95f4\u6233\n<\/em><\/em>\t\t\t$iftime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55UNIX\u65f6\u95f4\u6233\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t$this->debug(3, \"The conditional get's if-modified-since unixtime is $iftime\");\n\t\t\t\/\/\u5982\u679c\u8fd9\u4e2a\u65f6\u95f4\u5c0f\u4e8e1\u79d2\uff0c\u8bf4\u660e\u503c\u65e0\u6548\uff0c\u9000\u51fa\n<\/em><\/em>\t\t\tif($iftime < 1){\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6b64\u503c\u65e0\u6548\n<\/em><\/em>\t\t\t\t$this->debug(3, \"Got an invalid conditional get modified since time. Returning false.\");\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u6d4f\u89c8\u5668\u5b58\u50a8\u7684\u65f6\u95f4\u5c0f\u4e8e\u5b9e\u9645\u7f13\u5b58\u6587\u4ef6\u7684\u6700\u540e\u4fee\u6539\u65f6\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u8ddd\u4e0a\u6b21\u8bbf\u95ee\u540e\uff0c\u6587\u4ef6\u88ab\u66f4\u6539\u4e86\uff0c\u8981\u91cd\u65b0\u8bf7\u6c42\u9875\u9762\n<\/em><\/em>\t\t\tif($iftime < $mtime){\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6587\u4ef6\u5df2\u88ab\u66f4\u6539\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t$this->debug(3, \"File has been modified since last fetch.\");\n\t\t\t\treturn false;\n\t\t\t\/\/\u5426\u5219\u5c31\u4e0d\u7528\u91cd\u65b0\u8bf7\u6c42\u9875\u9762\uff0c\u76f4\u63a5\u8bfb\u53d6\u7f13\u5b58\n<\/em><\/em>\t\t\t} else {\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u7f13\u5b58\u6709\u6548\uff0c\u76f4\u63a5\u8bfb\u53d6\u7f13\u5b58\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t  \t$this->debug(3, \"File has not been modified since last get, so serving a 304.\");\n\t\t\t\t\/\/\u8bbe\u7f6eHTTP\u5934\u54cd\u5e94\u7801\u4e3a304\n<\/em><\/em>\t\t\t\theader ($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');\n\t\t\t\t\/\/\u8bb0\u5f55\u6b64\u6b21\u64cd\u4f5c\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\t\t$this->debug(1, \"Returning 304 not modified\");\n\t\t\t\t\/\/\u8bfb\u53d6\u6210\u529f\u8fd4\u56de\u771f\n<\/em><\/em>\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t\/\/\u6ca1\u6709\u8bfb\u53d6\u5230\u7f13\u5b58\uff0c\u8fd4\u56de\u5047\n<\/em><\/em>\t\treturn false;\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8fd0\u884c\u7f13\u5b58\u6587\u4ef6\u7684GC\u548c\u8bfb\u53d6\u670d\u52a1\u5668\u4e0a\u7684\u7f13\u5b58\u6587\u4ef6*\/<\/em>\n\tprotected function tryServerCache(){\n\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u5c06\u8bfb\u53d6\u670d\u52a1\u7aef\u7f13\u5b58\uff0c\u7ea7\u522b3\n<\/em><\/em>\t  \t$this->debug(3, \"Trying server cache\");\n\t  \t\/\/\u5982\u679c\u7f13\u5b58\u6587\u4ef6\u5b58\u5728\n<\/em><\/em>\t\tif(file_exists($this->cachefile)){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u7f13\u5b58\u6587\u4ef6\u5b58\u5728\n<\/em><\/em>\t\t  \t$this->debug(3, \"Cachefile {$this->cachefile} exists\");\n\t\t\t\/\/\u5982\u679c\u8bf7\u6c42\u7684\u662f\u5916\u90e8<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\n<\/em><\/em>\t\t\tif($this->isURL){\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8fd9\u662f\u4e00\u6b21\u5916\u90e8\u8bf7\u6c42\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t  \t$this->debug(3, \"This is an external request, so checking if the cachefile is empty which means the request failed previously.\");\n\t\t\t\t\/\/\u5982\u679c\u7f13\u5b58\u6587\u4ef6\u7684\u5927\u5c0f\u5c0f\u4e8e1\uff0c\u4e5f\u5c31\u662f\u8bf4\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\t\tif(filesize($this->cachefile) < 1){\n\t\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8fd9\u662f\u4e00\u4e2a\u7a7a\u7684\u7f13\u5b58\u6587\u4ef6\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t\t$this->debug(3, \"Found an empty cachefile indicating a failed earlier request. Checking how old it is.\");\n\t\t\t\t\t\/\/\u5982\u679c\u5df2\u5230\u4e86\u914d\u7f6e\u6587\u4ef6\u4e2d\u6e05\u7406\u65e0\u6548\u7f13\u5b58\u7684\u65f6\u95f4\n<\/em><\/em>\t\t\t\t\tif(time() - @filemtime($this->cachefile) > WAIT_BETWEEN_FETCH_ERRORS){\n\t\t\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8fd9\u6b21\u5220\u9664\u64cd\u4f5c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t\t  \t$this->debug(3, \"File is older than \" . WAIT_BETWEEN_FETCH_ERRORS . \" seconds. Deleting and returning false so app can try and load file.\");\n\t\t\t\t\t\t\/\/\u5220\u9664\u6b64\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\t\t\t\t@unlink($this->cachefile);\n\t\t\t\t\t\t\/\/\u8fd4\u56de\u5047\uff0c\u8bf4\u660e\u6ca1\u6709\u8bfb\u53d6\u5230\u670d\u52a1\u7aef\u7f13\u5b58\n<\/em><\/em>\t\t\t\t\t\treturn false;\n\t\t\t\t\t\/\/\u5426\u5219\uff0c\u7a7a\u7684\u7f13\u5b58\u6587\u4ef6\u8bf4\u660e\u4e0a\u6b21\u8bf7\u6c42\u5931\u8d25\uff0c\u6240\u4ee5\u8981\u5199\u9519\u8bef\u8bb0\u5f55\n<\/em><\/em>\t\t\t\t\t} else {\n\t\t\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u7a7a\u7684\u7f13\u5b58\u6587\u4ef6\u4f9d\u7136\u6709\u6548\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t\t  \t$this->debug(3, \"Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host.\");\n\t\t\t\t\t\t\/\/\u8bbe\u7f6e404\u9519\u8bef\n<\/em><\/em>\t\t\t\t\t\t$this->set404();\n\t\t\t\t\t\t\/\/\u8bbe\u7f6e\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t\t\t$this->error(\"An error occured fetching image.\");\n\t\t\t\t\t\t\/\/\u8fd4\u56de\u5047\u4ee3\u8868\u6ca1\u6709\u5f97\u5230\u7f13\u5b58\n<\/em><\/em>\t\t\t\t\t\treturn false; \n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\/\/\u5426\u5219\u5c31\u662f\u6b63\u786e\u7684\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\t} else {\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u5c06\u8981\u76f4\u63a5\u8bfb\u53d6\u7f13\u5b58\u6587\u4ef6\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t$this->debug(3, \"Trying to serve cachefile {$this->cachefile}\");\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u8f93\u51fa\u56fe\u50cf\u7f13\u5b58\u6210\u529f\n<\/em><\/em>\t\t\tif($this->serveCacheFile()){\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u7f13\u5b58\u6587\u4ef6\u4fe1\u606f\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t$this->debug(3, \"Succesfully served cachefile {$this->cachefile}\");\n\t\t\t\treturn true;\n\t\t\t\/\/\u5982\u679c\u4e0d\u6210\u529f\n<\/em><\/em>\t\t\t} else {\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t$this->debug(3, \"Failed to serve cachefile {$this->cachefile} - Deleting it from cache.\");\n\t\t\t\t\/\/\u5220\u9664\u6b64\u65e0\u6548\u7f13\u5b58\uff0c\u4ee5\u4fbf\u4e0b\u6b21\u8bf7\u6c42\u80fd\u91cd\u65b0\u521b\u5efa\n<\/em><\/em>\t\t\t\t@unlink($this->cachefile);\n\t\t\t\t\/\/\u540c\u6837\u8fd4\u56de\u771f,\u56e0\u4e3a\u5728serverCacheFile\u5df2\u7ecf\u8bb0\u5f55\u4e86\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f*\/<\/em>\n\tprotected function error($err){\n\t  \t\/\/\u5199\u8bb0\u5f55\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\uff0c\u7ea7\u522b3\n<\/em><\/em>\t  \t$this->debug(3, \"Adding error message: $err\");\n\t\t\/\/\u8bb0\u5f55\u5230\u9519\u8bef\u4fe1\u606f\u6570\u7ec4\n<\/em><\/em>\t\t$this->errors[] = $err;\n\t\treturn false;\n\t}\n\t\/*\u6d4b\u51fd\u6570\u7528\u6765\u68c0\u6d4b\u5b58\u50a8\u9519\u8bef\u4fe1\u606f\u7684\u6570\u7ec4\u4e2d\u662f\u5426\u6709\u5185\u5bb9\uff0c\u4e5f\u5c31\u662f\u8bf4\u5728\u4e0a\u4e00\u4e2a\u64cd\u4f5c\u4e2d\uff0c\u662f\u5426\u6709\u9519\u8bef*\/<\/em>\n\tprotected function haveErrors(){\n\t\tif(sizeof($this->errors) > 0){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\/*\u6b64\u51fd\u6570\u8f93\u51fa\u5df2\u5b58\u50a8\u7684\u9519\u8bef\u4fe1\u606f*\/<\/em>\n\tprotected function serveErrors(){\n\t  \t\/\/\u8bbe\u7f6ehttp\u5934\n<\/em><\/em>\t  header ($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');\n\t  \t\/\/\u5faa\u73af\u8f93\u51fa\u9519\u8bef\u5217\u8868\u4fe1\u606f\n<\/em><\/em>\t\t$html = '<ul>';\n\t\tforeach($this->errors as $err){\n\t\t\t$html .= '<li>' . htmlentities($err) . '<\/li>';\n\t\t}\n\t\t$html .= '<\/ul>';\n\t\t\/\/\u8f93\u51fa\u5176\u4ed6\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\techo '<h1>A TimThumb error has occured<\/h1>The following error(s) occured:<br \/>' . $html . '<br \/>';\n\t\techo '<br \/>Query String : ' . htmlentities ($_SERVER['QUERY_STRING']);\n\t\techo '<br \/>TimThumb version : ' . VERSION . '<\/pre>';\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8bfb\u53d6\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>*\/<\/em>\n\tprotected function serveInternalImage(){\n\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\n<\/em><\/em>\t  \t$this->debug(3, \"Local image path is $this->localImage\");\n\t  \t\/\/\u5982\u679c\u5730\u5740\u65e0\u6548\n<\/em><\/em>\t\tif(! $this->localImage){\n\t\t  \t\/\/\u8bb0\u5f55\u6b64\u9519\u8bef\uff0c\u5e76\u9000\u51fa\u6267\u884c\n<\/em><\/em>\t\t\t$this->sanityFail(\"localImage not set after verifying it earlier in the code.\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u83b7\u53d6\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5927\u5c0f\n<\/em><\/em>\t\t$fileSize = filesize($this->localImage);\n\t\t\/\/\u5982\u679c\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u5c3a\u5bf8\u8d85\u8fc7\u914d\u7f6e\u6587\u4ef6\u7684\u76f8\u5173\u8bbe\u7f6e\n<\/em><\/em>\t\tif($fileSize > MAX_FILE_SIZE){\n\t\t  \t\/\/\u8bb0\u5f55\u9519\u8bef\u539f\u56e0\uff0c\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\t$this->error(\"The file you specified is greater than the maximum allowed file size.\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u5982\u679c\u83b7\u53d6\u5230\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5c3a\u5bf8\u65e0\u6548\n<\/em><\/em>\t\tif($fileSize <= 0){\n\t\t  \t\/\/\u8bb0\u5f55\u9519\u8bef\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\t$this->error(\"The file you specified is <= 0 bytes.\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u5982\u679c\u901a\u8fc7\u4e86\u4ee5\u4e0a\u9a8c\u8bc1\uff0c\u5219\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u5c06\u7528processImageAndWriteToCache\u51fd\u6570<strong>\u5904\u7406<\/strong>\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t$this->debug(3, \"Calling processImageAndWriteToCache() for local image.\");\n\t\t\/\/<strong>\u5904\u7406<\/strong>\u6210\u529f\u5219\u4ece\u7f13\u5b58\u8fd4\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\tif($this->processImageAndWriteToCache($this->localImage)){\n\t\t\t$this->serveCacheFile();\n\t\t\treturn true;\n\t\t\/\/\u5931\u8d25\u5219\u8fd4\u56de\u5047\n<\/em><\/em>\t\t} else { \n\t\t\treturn false;\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u6e05\u7406\u7f13\u5b58*\/<\/em>\n\tprotected function cleanCache(){\n\t\t\/\/\u5982\u679c\u5b9a\u4e49\u7684\u7f13\u5b58\u65f6\u95f4\u5c0f\u4e8e0\uff0c\u5219\u9000\u51fa\n<\/em><\/em>\t\tif (FILE_CACHE_TIME_BETWEEN_CLEANS < 0) {\n\t\t\treturn;\n\t\t}\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6e05\u9664\u7f13\u5b58\u64cd\u4f5c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t$this->debug(3, \"cleanCache() called\");\n\t\t\/\/\u6b64\u6587\u4ef6\u4e3a\u8bb0\u5f55\u4e0a\u6b21\u8fdb\u884c\u6e05\u9664\u7f13\u5b58\u64cd\u4f5c\u7684\u65f6\u95f4\u6233\u6587\u4ef6\n<\/em><\/em>\t\t$lastCleanFile = $this->cacheDirectory . '\/timthumb_cacheLastCleanTime.touch';\n\t\t\n\t\t\/\/\u5982\u679c\u4e0a\u9762\u5b9a\u4e49\u7684\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u8bf4\u660e\u8fd9\u662f\u7b2c\u4e00\u6b21\u8fdb\u884c\u6e05\u9664\u7f13\u5b58\u64cd\u4f5c\uff0c\u521b\u5efa\u6b64\u6587\u4ef6\u5e76\u8fd4\u56de\u7a7a\u5373\u53ef\n<\/em><\/em>\t\tif(! is_file($lastCleanFile)){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u521b\u5efa\u6587\u4ef6\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t  \t$this->debug(1, \"File tracking last clean doesn't exist. Creating $lastCleanFile\");\n\t\t\t\/\/\u521b\u5efa\u6b64\u6587\u4ef6\n<\/em><\/em>\t\t\tif (!touch($lastCleanFile)) {\n\t\t\t  \t\/\/\u5931\u8d25\u7684\u8bdd\u62a5\u9519\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\t\t$this->error(\"Could not create cache clean timestamp file.\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\/\/\u5982\u679c\u5df2\u8d85\u8fc7\u7f13\u5b58\u65f6\u95f4\n<\/em><\/em>\t\tif(@filemtime($lastCleanFile) < (time() - FILE_CACHE_TIME_BETWEEN_CLEANS) ){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u4e0b\u9762\u8fdb\u884c\u7684\u6e05\u9664\u7f13\u5b58\u64cd\u4f5c\n<\/em><\/em>\t\t\t$this->debug(1, \"Cache was last cleaned more than \" . FILE_CACHE_TIME_BETWEEN_CLEANS . \" seconds ago. Cleaning now.\");\n\t\t\t\/\/\u521b\u5efa\u65b0\u7684\u6e05\u9664\u7f13\u5b58\u65f6\u95f4\u6233\u6587\u4ef6\n<\/em><\/em>\t\t\tif (!touch($lastCleanFile)) {\n\t\t\t  \t\/\/\u5931\u8d25\u7684\u8bdd\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\t\t$this->error(\"Could not create cache clean timestamp file.\");\n\t\t\t}\n\t\t\t\/\/\u6b64\u6570\u7ec4\u5b58\u7684\u662f\u6240\u6709\u7f13\u5b58\u6587\u4ef6\uff0c\u6839\u636e\u524d\u9762\u5b9a\u4e49\u7684\u7f13\u5b58\u6587\u4ef6\u76ee\u5f55\u548c\u7f13\u5b58\u6587\u4ef6\u540e\u7f00\u5f97\u5230\u7684\n<\/em><\/em>\t\t\t$files = glob($this->cacheDirectory . '\/*' . FILE_CACHE_SUFFIX);\n\t\t\t\/\/\u5982\u679c\u6709\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\tif ($files) {\n\t\t\t  \t\/\/\u8ba1\u7b97\u5f53\u524d\u65f6\u95f4\u548c\u7f13\u5b58\u6700\u5927\u751f\u5b58\u65f6\u95f4\u7684\u5dee\u503c\uff0c\u7528\u4e8e\u4e0b\u9762\u5224\u65ad\u7f13\u5b58\u6587\u4ef6\u662f\u5426\u5220\u9664\n<\/em><\/em>\t\t\t  \t$timeAgo = time() - FILE_CACHE_MAX_FILE_AGE;\n\t\t\t\t\/\/\u904d\u5386\u7f13\u5b58\u6587\u4ef6\u6570\u7ec4\n<\/em><\/em>\t\t\t\tforeach($files as $file){\n\t\t\t\t  \t\/\/\u5982\u679c\u6587\u4ef6\u521b\u5efa\u65f6\u95f4\u5c0f\u4e8e\u4e0a\u9762\u8ba1\u7b97\u7684\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\u6b64\u7f13\u5b58\u6587\u4ef6\u7684\u6b7b\u671f\u5230\u4e86\uff0c\u5c31\u5220\u9664\u5b83\n<\/em><\/em>\t\t\t\t  \tif(@filemtime($file) < $timeAgo){\n\t\t\t\t    \t\t\/\/\u8bb0\u5f55\u5220\u9664\u7f13\u5b58\u6587\u4ef6\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t\t\t\t$this->debug(3, \"Deleting cache file $file older than max age: \" . FILE_CACHE_MAX_FILE_AGE . \" seconds\");\n\t\t\t\t\t\t@unlink($file);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t\/\/\u5982\u679c\u6ca1\u8d85\u8fc7\u7f13\u5b58\u65f6\u95f4\uff0c\u5219\u4e0d\u7528\u6e05\u9664\n<\/em><\/em>\t\t} else {\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u4e0d\u7528\u6e05\u9664\u7f13\u5b58\n<\/em><\/em>\t\t\t$this->debug(3, \"Cache was cleaned less than \" . FILE_CACHE_TIME_BETWEEN_CLEANS . \" seconds ago so no cleaning needed.\");\n\t\t}\n\t\treturn false;\n\t}\n\t\/*\u6838\u5fc3\u51fd\u6570\uff0c<strong>\u5904\u7406<\/strong><strong><strong>\u56fe\u7247<\/strong><\/strong>\u5e76\u5199\u5165\u7f13\u5b58*\/<\/em>\n\tprotected function processImageAndWriteToCache($localImage){\n\t  \t\/\/\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4fe1\u606f\n<\/em><\/em>\t  \t$sData = getimagesize($localImage);\n\t\t\/\/\u56fe\u50cf\u7c7b\u578b\u6807\u8bb0\n<\/em><\/em>\t\t$origType = $sData[2];\n\t\t\/\/mime\u7c7b\u578b\n<\/em><\/em>\t\t$mimeType = $sData['mime'];\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u4f20\u5165\u56fe\u50cf\u7684mime\u7c7b\u578b\n<\/em><\/em>\t\t$this->debug(3, \"Mime type of image is $mimeType\");\n\t\t\/\/\u8fdb\u884c\u56fe\u50cfmime\u7c7b\u578b\u9a8c\u8bc1\uff0c\u53ea\u5141\u8bb8gif , jpg \u548c png\n<\/em><\/em>\t\tif(! preg_match('\/^image\/(?:gif|jpg|jpeg|png)$\/i', $mimeType)){\n\t\t  \t\/\/\u5982\u679c\u4e0d\u662f\u8fd9\u56db\u79cd\u7c7b\u578b\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\uff0c\u5e76\u9000\u51fa\u811a\u672c\n<\/em><\/em>\t\t\treturn $this->error(\"The image being resized is not a valid gif, jpg or png.\");\n\t\t}\n\t\t\/\/<strong><strong>\u56fe\u7247<\/strong><\/strong><strong>\u5904\u7406<\/strong>\u9700\u8981GD\u5e93\u652f\u6301\uff0c\u8fd9\u91cc\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u4e86GD\u5e93\n<\/em><\/em>\t\tif (!function_exists ('imagecreatetruecolor')) {\n\t\t    \/\/\u6ca1\u6709\u5b89\u88c5\u7684\u8bdd\u63a8\u51fa\u811a\u672c\n<\/em><\/em>\t\t    return $this->error('GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library');\n\t\t}\n\t\t\/\/\u5982\u679c\u5b89\u88c5\u4e86GD\u5e93\uff0c\u5e76\u4e14\u652f\u6301\u56fe\u50cf\u8fc7\u6ee4\u5668\u51fd\u6570imagefilter\uff0c\u4e14\u652f\u6301IMG_FILTER_NEGATE\u5e38\u91cf\n<\/em><\/em>\t\tif (function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {\n\t\t  \t\/\/\u5b9a\u4e49\u4e00\u4e2a\u8fc7\u6ee4\u5668\u6548\u679c\u6570\u7ec4\uff0c\u540e\u9762\u7684\u6570\u5b57\u4ee3\u8868\u9700\u8981\u989d\u5916\u4f20\u5165\u7684\u53c2\u6570\n<\/em><\/em>\t\t  \t$imageFilters = array (\n\t\t    \t\t\/\/\u8d1f\u7247\n<\/em><\/em>\t\t\t  \t1 => array (IMG_FILTER_NEGATE, 0),\n\t\t\t\t\/\/\u9ed1\u767d\u7684\n<\/em><\/em>\t\t\t\t2 => array (IMG_FILTER_GRAYSCALE, 0),\n\t\t\t\t\/\/\u4eae\u5ea6\u7ea7\u522b\n<\/em><\/em>\t\t\t\t3 => array (IMG_FILTER_BRIGHTNESS, 1),\n\t\t\t\t\/\/\u5bf9\u6bd4\u5ea6\u7ea7\u522b\n<\/em><\/em>\t\t\t\t4 => array (IMG_FILTER_CONTRAST, 1),\n\t\t\t\t\/\/\u56fe\u50cf\u8f6c\u6362\u4e3a\u5236\u5b9a\u989c\u8272\n<\/em><\/em>\t\t\t\t5 => array (IMG_FILTER_COLORIZE, 4),\n\t\t\t\t\/\/\u7a81\u51fa\u8fb9\u7f18\n<\/em><\/em>\t\t\t\t6 => array (IMG_FILTER_EDGEDETECT, 0),\n\t\t\t\t\/\/\u6d6e\u96d5\n<\/em><\/em>\t\t\t\t7 => array (IMG_FILTER_EMBOSS, 0),\n\t\t\t\t\/\/\u7528\u9ad8\u65af\u7b97\u6cd5\u6a21\u7cca\u56fe\u50cf\n<\/em><\/em>\t\t\t\t8 => array (IMG_FILTER_GAUSSIAN_BLUR, 0),\n\t\t\t\t\/\/\u6a21\u7cca\u56fe\u50cf\n<\/em><\/em>\t\t\t\t9 => array (IMG_FILTER_SELECTIVE_BLUR, 0),\n\t\t\t\t\/\/\u5e73\u5747\u79fb\u9664\u6cd5\u6765\u8fbe\u5230\u8f6e\u5ed3\u6548\u679c\n<\/em><\/em>\t\t\t\t10 => array (IMG_FILTER_MEAN_REMOVAL, 0),\n\t\t\t\t\/\/\u5e73\u6ed1<strong>\u5904\u7406<\/strong>\n<\/em><\/em>\t\t\t\t11 => array (IMG_FILTER_SMOOTH, 0),\n\t\t\t);\n\t\t}\n\n\t\t\/\/\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5bbd\u5ea6\uff0c\u7531get\u4e2dw\u53c2\u6570\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a0\t\t\n<\/em><\/em>\t\t$new_width =  (int) abs ($this->param('w', 0));\n\t\t\/\/\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u9ad8\u5ea6\uff0c\u7531get\u4e2dh\u53c2\u6570\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a0\n<\/em><\/em>\t\t$new_height = (int) abs ($this->param('h', 0));\n\t\t\/\/\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7f29\u653e\u6a21\u5f0f\uff0c\u7531get\u4e2dzc\u53c2\u6570\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a\u914d\u7f6e\u6587\u4ef6\u4e2dDEFAULT_ZC\u7684\u503c\n<\/em><\/em>\t\t$zoom_crop = (int) $this->param('zc', DEFAULT_ZC);\n\t\t\/\/\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u8d28\u91cf\uff0c\u7531get\u4e2dq\u53c2\u6570\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a\u914d\u7f6e\u6587\u4ef6\u4e2dDEFAULT_Q\u7684\u503c\n<\/em><\/em>\t\t$quality = (int) abs ($this->param('q', DEFAULT_Q));\n\t\t\/\/\u88c1\u526a\u7684\u4f4d\u7f6e\n<\/em><\/em>\t\t$align = $this->cropTop ? 't' : $this->param('a', 'c');\n\t\t\/\/\u9700\u8981\u8fdb\u884c\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong><strong>\u5904\u7406<\/strong>\u64cd\u4f5c\uff0c\u591a\u4e2a\u8fc7\u6ee4\u5668\u7528\"|\"\u5206\u5272\uff0c\u53ef\u9009\u53c2\u6570\u8bf7\u53c2\u770b$imageFilters\u5904\u7684\u6ce8\u91ca\uff0c\u7531\u4e8e\u4e0d\u540c\u7684\u8fc7\u6ee4\u5668\u9700\u8981\u7684\u53c2\u6570\u4e0d\u540c\uff0c\u5982\u4e00\u4e2a\u8fc7\u6ee4\u5668\u9700\u8981\u591a\u4e2a\u53c2\u6570\uff0c\u591a\u4e2a\u53c2\u6570\u7528,\u5206\u9694\u3002\u4f8b:1,2|3,1,1  \u4ee3\u8868\u5bf9\u56fe\u50cf\u5206\u522b\u5e94\u75281\u548c3\u8fc7\u6ee4\u6548\u679c\uff0c1\u548c3\u6240\u5bf9\u5e94\u7684\u8fc7\u6ee4\u6548\u679c\u662f\u7531$imageFilters\u6570\u7ec4\u786e\u5b9a\u7684\uff0c\u5176\u4e2d1\u53f7\u8fc7\u6ee4\u5668\u8fd8\u9700\u8981\u4e00\u4e2a\u989d\u5916\u7684\u53c2\u6570\uff0c\u8fd9\u91cc\u4f20\u4e861\uff0c3\u53f7\u8fc7\u6ee4\u5668\u8fd8\u9700\u89812\u4e2a\u989d\u5916\u7684\u53c2\u6570\uff0c\u8fd9\u91cc\u4f20\u4e861\u548c1.\n<\/em><\/em>\t\t$filters = $this->param('f', DEFAULT_F);\n\t\t\/\/\u662f\u5426\u5bf9<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8fdb\u884c\u9510\u5316\uff0c\u7531get\u4e2ds\u53c2\u6570\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a\u914d\u7f6e\u6587\u4ef6\u4e2dDEFAULT_S\u7684\u503c\n<\/em><\/em>\t\t$sharpen = (bool) $this->param('s', DEFAULT_S);\n\t\t\/\/\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u9ed8\u8ba4\u80cc\u666f\u753b\u5e03\u989c\u8272\uff0c\u7531get\u4e2dcc\u53c2\u6570\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4e3a\u914d\u7f6e\u6587\u4ef6\u4e2dDEFAULT_CC\u7684\u503c\n<\/em><\/em>\t\t$canvas_color = $this->param('cc', DEFAULT_CC);\n\t\t\/\/\u751f\u6210png<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u80cc\u666f\u662f\u5426\u900f\u660e\n<\/em><\/em>\t\t$canvas_trans = (bool) $this->param('ct', '1');\n\n\t\t\/\/ \u5982\u679c\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u90fd\u6ca1\u6709\u6307\u5b9a\uff0c\u8bbe\u7f6e\u4ed6\u4eec\u4e3a100*100\n<\/em><\/em>\t\tif ($new_width == 0 && $new_height == 0) {\n\t\t    $new_width = 100;\n\t\t    $new_height = 100;\n\t\t}\n\n\t\t\/\/ \u9650\u5236\u6700\u5927\u9ad8\u5ea6\u548c\u6700\u5927\u5bbd\u5ea6\n<\/em><\/em>\t\t$new_width = min ($new_width, MAX_WIDTH);\n\t\t$new_height = min ($new_height, MAX_HEIGHT);\n\n\t\t\/\/ \u68c0\u6d4b\u5e76\u8bbe\u7f6ephp\u8fd0\u884c\u6700\u5927\u5360\u7528\u5185\u5b58\n<\/em><\/em>\t\t$this->setMemoryLimit();\n\n\t\t\/\/ \u6253\u5f00\u56fe\u50cf\u8d44\u6e90\n<\/em><\/em>\t\t$image = $this->openImage ($mimeType, $localImage);\n\t\t\/\/\u5982\u679c\u6253\u5f00\u5931\u8d25\uff0c\u8bb0\u5f55\u4fe1\u606f\u5e76\u9000\u51fa\u811a\u672c\n<\/em><\/em>\t\tif ($image === false) {\n\t\t\treturn $this->error('Unable to open image.');\n\t\t}\n\n\t\t\/\/ \u83b7\u5f97\u539f\u59cb<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u4e5f\u5c31\u662f\u4e0a\u9762\u6253\u5f00<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u5bbd\u548c\u9ad8\n<\/em><\/em>\t\t$width = imagesx ($image);\n\t\t$height = imagesy ($image);\n\t\t$origin_x = 0;\n\t\t$origin_y = 0;\n\n\t\t\/\/ \u5982\u679c\u65b0\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u5bbd\u6216\u9ad8\u6ca1\u6709\u6307\u5b9a\uff0c\u5219\u7528\u6b64\u7b49\u6bd4\u7b97\u6cd5\u7b97\u51fa\u9ad8\u6216\u5bbd\u7684\u503c\n<\/em><\/em>\t\tif ($new_width && !$new_height) {\n\t\t\t$new_height = floor ($height * ($new_width \/ $width));\n\t\t} else if ($new_height && !$new_width) {\n\t\t\t$new_width = floor ($width * ($new_height \/ $height));\n\t\t}\n\n\t\t\/\/ \u5982\u679c\u7f29\u653e\u6a21\u5f0f\u9009\u62e9\u7684\u662f3\uff0c\u4e5f\u5c31\u662f\u8bf4get\u4e2dzc=3\u6216\u8005\u914d\u7f6e\u6587\u4ef6\u4e2dDEFAULT_ZC=3\uff0c\u5219\u8fdb\u884c\u7b49\u6bd4\u7f29\u653e,\u4e0d\u88c1\u526a\n<\/em><\/em>\t\tif ($zoom_crop == 3) {\n\n\t\t\t$final_height = $height * ($new_width \/ $width);\n\t\t\t\/\/\u6839\u636e\u7b49\u6bd4\u7b97\u6cd5\u8bbe\u7f6e\u7b49\u6bd4\u8ba1\u7b97\u540e\u7684\u5bbd\u6216\u9ad8\n<\/em><\/em>\t\t\tif ($final_height > $new_height) {\n\t\t\t\t$new_width = $width * ($new_height \/ $height);\n\t\t\t} else {\n\t\t\t\t$new_height = $final_height;\n\t\t\t}\n\n\t\t}\n\n\t\t\/\/ \u5229\u7528<strong>\u5904\u7406<\/strong>\u5b8c\u6bd5\u7684\u957f\u548c\u5bbd\u521b\u5efa\u65b0\u753b\u5e03\uff0c\n<\/em><\/em>\t\t$canvas = imagecreatetruecolor ($new_width, $new_height);\n\t\t\/\/\u5173\u95ed\u6df7\u8272\u6a21\u5f0f\uff0c\u4e5f\u5c31\u662f\u628aPNG\u7684alpha\u503c\u4fdd\u5b58\uff0c\u4ece\u800c\u4f7f\u80cc\u666f\u900f\u660e\n<\/em><\/em>\t\timagealphablending ($canvas, false);\n\t\t\/\/\u8fdb\u884c\u9ed8\u8ba4\u753b\u5e03\u989c\u8272\u7684\u68c0\u6d4b\u5e76\u8f6c\u6362\uff0c\u5982\u679c\u7ed9\u51fa\u7684\u662f3\u4e2a\u5b57\u7b26\u957f\u5ea6\u8868\u793a\u7684\u989c\u8272\u503c\n<\/em><\/em>\t\tif (strlen($canvas_color) == 3) { \/\/if is 3-char notation, edit string into 6-char notation\n<\/em><\/em>\t\t  \t\/\/\u8f6c\u6362\u4e3a6\u4e2a\u5b57\u7b26\u8868\u793a\u7684\u989c\u8272\u503c\n<\/em><\/em>\t\t  \t$canvas_color =  str_repeat(substr($canvas_color, 0, 1), 2) . str_repeat(substr($canvas_color, 1, 1), 2) . str_repeat(substr($canvas_color, 2, 1), 2); \n\t\t\/\/\u5982\u679c\u4e0d\u662f3\u4e2a\u957f\u5ea6\u4e5f\u4e0d\u662f6\u4e2a\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u4e3a\u975e\u6cd5\u5b57\u7b26\u4e32\uff0c\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u503c\n<\/em><\/em>\t\t} else if (strlen($canvas_color) != 6) {\n\t\t\t$canvas_color = DEFAULT_CC;\n \t\t}\n\t\t\/\/\u5c06\u4e0a\u9762\u5f97\u5230\u7684R \u3001G \u3001B \u4e09\u79cd\u989c\u8272\u503c\u8f6c\u6362\u4e3a10\u8fdb\u5236\u8868\u793a\n<\/em><\/em>\t\t$canvas_color_R = hexdec (substr ($canvas_color, 0, 2));\n\t\t$canvas_color_G = hexdec (substr ($canvas_color, 2, 2));\n\t\t$canvas_color_B = hexdec (substr ($canvas_color, 4, 2));\n\n\t\t\/\/ \u5982\u679c\u4f20\u5165<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u683c\u5f0f\u662fpng\uff0c\u5e76\u4e14\u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6epng\u80cc\u666f\u989c\u8272\u4e3a\u900f\u660e\uff0c\u5e76\u4e14\u5728get\u4f20\u5165\u4e86ct\u7684\u503c\u4e3a\u771f\uff0c\u90a3\u4e48\u5c31\u8bbe\u7f6e\u80cc\u666f\u989c\u8272\u4e3a\u900f\u660e\n<\/em><\/em>\t\tif(preg_match('\/^image\/png$\/i', $mimeType) && !PNG_IS_TRANSPARENT && $canvas_trans){ \n\t\t  \t$color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 127);\n\t\t\/\/\u53cd\u4e4b\u8bbe\u7f6e\u4e3a\u4e0d\u900f\u660e\n<\/em><\/em>\t\t}else{\n\t\t\t$color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 0);\n\t\t}\n\n\t\t\/\/ \u4f7f\u7528\u5206\u914d\u7684\u989c\u8272\u586b\u5145\u80cc\u666f\n<\/em><\/em>\t\timagefill ($canvas, 0, 0, $color);\n\t\t\n\n\t\t\/\/ \u5982\u679c\u7f29\u653e\u6a21\u5f0f\u9009\u62e9\u7684\u662f2\uff0c\u90a3\u4e48\u753b\u5e03\u7684\u4f53\u79ef\u662f\u6309\u4f20\u5165\u7684\u503c\u521b\u5efa\u7684\uff0c\u5e76\u8ba1\u7b97\u51fa\u8fb9\u6846\u7684\u5bbd\u5ea6\n<\/em><\/em>\t\tif ($zoom_crop == 2) {\n\t\t  \t\/\/\u7b49\u6bd4\u7f29\u653e\u7684\u9ad8\u5ea6\n<\/em><\/em>\t\t\t$final_height = $height * ($new_width \/ $width);\n\t\t\t\/\/\u5982\u679c\u8ba1\u7b97\u51fa\u7684\u7b49\u6bd4\u9ad8\u5ea6\uff0c\u5927\u4e8e\u4f20\u5165\u7684\u9ad8\u5ea6\n<\/em><\/em>\t\t\tif ($final_height > $new_height) {\n\t\t\t\t\/\/origin_x\u7b49\u4e8e\u4f20\u5165\u7684\u65b0\u9ad8\u5ea6\u7684\u4e8c\u5206\u4e4b\u4e00\n<\/em><\/em>\t\t\t  \t$origin_x = $new_width \/ 2;\n\t\t\t  \t\/\/\u8bbe\u7f6e\u65b0\u5bbd\u5ea6\u4e3a\u7b49\u6bd4\u8ba1\u7b97\u51fa\u7684\u503c\n<\/em><\/em>\t\t\t\t$new_width = $width * ($new_height \/ $height);\n\t\t\t\t\/\/\u8ba1\u7b97\u51fa\u4e24\u6b21origin_x\u7684\u5dee\u503c\n<\/em><\/em>\t\t\t\t$origin_x = round ($origin_x - ($new_width \/ 2));\n\t\t\t\/\/\u5426\u5219\uff0c\u8ba1\u7b97\u51fa\u4e24\u6b21origin_y\u7684\u5dee\u503c\n<\/em><\/em>\t\t\t} else {\n\t\t\t\t$origin_y = $new_height \/ 2;\n\t\t\t\t$new_height = $final_height;\n\t\t\t\t$origin_y = round ($origin_y - ($new_height \/ 2));\n\n\t\t\t}\n\n\t\t}\n\n\t\t\/\/ \u4fdd\u5b58\u56fe\u50cf\u65f6\u4fdd\u5b58\u5b8c\u6574\u7684alpha\u4fe1\u606f\n<\/em><\/em>\t\timagesavealpha ($canvas, true);\n\n\t\t\/\/\u5982\u679c\u7f29\u653e\u6a21\u5f0f\u9009\u62e9\u7684\u662f1\u62162\u62163\n<\/em><\/em>\t\tif ($zoom_crop > 0) {\n\n\t\t  \t$src_x = $src_y = 0;\n\t\t\t\/\/<strong><strong>\u56fe\u7247<\/strong><\/strong>\u539f\u5bbd\u5ea6\n<\/em><\/em>\t\t\t$src_w = $width;\n\t\t\t\/\/<strong><strong>\u56fe\u7247<\/strong><\/strong>\u539f\u9ad8\u5ea6\n<\/em><\/em>\t\t\t$src_h = $height;\n\n\t\t\t\/\/<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7eb5\u6a2a\u6bd4\n<\/em><\/em>\t\t\t$cmp_x = $width \/ $new_width;\n\t\t\t$cmp_y = $height \/ $new_height;\n\n\t\t\t\/\/\u88c1\u526a\u7b97\u6cd5\n<\/em><\/em>\t\t\tif ($cmp_x > $cmp_y) {\n\t\t\t\t$src_w = round ($width \/ $cmp_x * $cmp_y);\n\t\t\t\t$src_x = round (($width - ($width \/ $cmp_x * $cmp_y)) \/ 2);\n\n\t\t\t} else if ($cmp_y > $cmp_x) {\n\n\t\t\t\t$src_h = round ($height \/ $cmp_y * $cmp_x);\n\t\t\t\t$src_y = round (($height - ($height \/ $cmp_y * $cmp_x)) \/ 2);\n\n\t\t\t}\n\n\t\t\t\/\/ \u6839\u636e\u4f20\u5165\u53c2\u6570\u7b97\u51fa\u88c1\u526a\u7684\u4f4d\u7f6e\n<\/em><\/em>\t\t\tif ($align) {\n\t\t\t\tif (strpos ($align, 't') !== false) {\n\t\t\t\t\t$src_y = 0;\n\t\t\t\t}\n\t\t\t\tif (strpos ($align, 'b') !== false) {\n\t\t\t\t\t$src_y = $height - $src_h;\n\t\t\t\t}\n\t\t\t\tif (strpos ($align, 'l') !== false) {\n\t\t\t\t\t$src_x = 0;\n\t\t\t\t}\n\t\t\t\tif (strpos ($align, 'r') !== false) {\n\t\t\t\t\t$src_x = $width - $src_w;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t\/\/\u5c06\u56fe\u50cf\u6839\u636e\u7b97\u6cd5\u8fdb\u884c\u88c1\u526a\uff0c\u5e76\u62f7\u8d1d\u5230\u80cc\u666f<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4e0a\n<\/em><\/em>\t\t\timagecopyresampled ($canvas, $image, $origin_x, $origin_y, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h);\n\n\t\t} else {\n\n\t\t\t\/\/\u88c1\u526a\u6a21\u5f0f\u9009\u62e9\u7684\u662f0\uff0c\u5219\u4e0d\u8fdb\u884c\u88c1\u526a\uff0c\u5e76\u751f\u6210\u56fe\u50cf\n<\/em><\/em>\t\t\timagecopyresampled ($canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);\n\n\t\t}\n\t\t\/\/\u5982\u679c\u5b9a\u4e49\u4e86<strong><strong>\u56fe\u7247<\/strong><\/strong><strong>\u5904\u7406<\/strong>\u64cd\u4f5c\uff0c\u5e76\u4e14\u652f\u6301<strong><strong>\u56fe\u7247<\/strong><\/strong><strong>\u5904\u7406<\/strong>\u51fd\u6570\n<\/em><\/em>\t\tif ($filters != '' && function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {\n\t\t\t\/\/ \u5206\u5272\u6bcf\u4e2a\u8fc7\u6ee4<strong>\u5904\u7406<\/strong>\n<\/em><\/em>\t\t\t$filterList = explode ('|', $filters);\n\t\t\tforeach ($filterList as $fl) {\n\t\t\t  \t\/\/\u5206\u5272\u4e00\u4e2a\u8fc7\u6ee4\u64cd\u4f5c\u4e2d\u7684\u53c2\u6570\n<\/em><\/em>\t\t\t  \t$filterSettings = explode (',', $fl);\n\t\t\t\t\/\/\u5982\u679c\u6240\u9009\u7684\u8fc7\u6ee4\u64cd\u4f5c\u5b58\u5728\n<\/em><\/em>\t\t\t\tif (isset ($imageFilters[$filterSettings[0]])) {\n\t\t\t\t\t\/\/\u5c06\u6240\u6709\u53c2\u6570\u8f6c\u4e3aint\u7c7b\u578b\n<\/em><\/em>\t\t\t\t\tfor ($i = 0; $i < 4; $i ++) {\n\t\t\t\t\t\tif (!isset ($filterSettings[$i])) {\n\t\t\t\t\t\t\t$filterSettings[$i] = null;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t$filterSettings[$i] = (int) $filterSettings[$i];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\/\/\u6839\u636e$imageFilters\u4e2d\u5b9a\u4e49\u7684\u6bcf\u4e2a\u8fc7\u6ee4\u6548\u679c\u9700\u8981\u7684\u53c2\u6570\u7684\u4e0d\u540c\uff0c\u5bf9\u56fe\u50cf\u5e94\u7528\u8fc7\u6ee4\u5668\u6548\u679c\n<\/em><\/em>\t\t\t\t\tswitch ($imageFilters[$filterSettings[0]][1]) {\n\n\t\t\t\t\t\tcase 1:\n\n\t\t\t\t\t\t\timagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1]);\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 2:\n\n\t\t\t\t\t\t\timagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2]);\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 3:\n\n\t\t\t\t\t\t\timagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3]);\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 4:\n\n\t\t\t\t\t\t\timagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3], $filterSettings[4]);\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tdefault:\n\n\t\t\t\t\t\t\timagefilter ($canvas, $imageFilters[$filterSettings[0]][0]);\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t\/\/ \u5982\u679c\u8bbe\u7f6e\u4e86\u9510\u5316\u503c\uff0c\u5e76\u4e14\u7cfb\u7edf\u652f\u6301\u9510\u5316\u51fd\u6570\uff0c\u5219\u8fdb\u884c\u9510\u5316\u64cd\u4f5c\n<\/em><\/em>\t\tif ($sharpen && function_exists ('imageconvolution')) {\n\n\t\t\t$sharpenMatrix = array (\n\t\t\t\t\tarray (-1,-1,-1),\n\t\t\t\t\tarray (-1,16,-1),\n\t\t\t\t\tarray (-1,-1,-1),\n\t\t\t\t\t);\n\n\t\t\t$divisor = 8;\n\t\t\t$offset = 0;\n\n\t\t\timageconvolution ($canvas, $sharpenMatrix, $divisor, $offset);\n\n\t\t}\n\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u662fPNG\u6216\u8005GIF\uff0c\u5219\u7528imagetruecolortopalette\u6765\u51cf\u5c0f\u4ed6\u4eec\u7684\u4f53\u79ef\n<\/em><\/em>\t\tif ( (IMAGETYPE_PNG == $origType || IMAGETYPE_GIF == $origType) && function_exists('imageistruecolor') && !imageistruecolor( $image ) && imagecolortransparent( $image ) > 0 ){\n\t\t\timagetruecolortopalette( $canvas, false, imagecolorstotal( $image ) );\n\t\t}\n\t\t\/\/\u6839\u636e\u751f\u6210\u7684\u4e0d\u540c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7c7b\u578b\uff0c\u751f\u6210<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7f13\u5b58,$imgType\u7684\u503c\u7528\u4e8e\u751f\u6210\u5b89\u5168\u5934\n<\/em><\/em>\t\t$imgType = \"\";\n\t\t$tempfile = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');\n\t\tif(preg_match('\/^image\/(?:jpg|jpeg)$\/i', $mimeType)){ \n\t\t\t$imgType = 'jpg';\n\t\t\timagejpeg($canvas, $tempfile, $quality); \n\t\t} else if(preg_match('\/^image\/png$\/i', $mimeType)){ \n\t\t\t$imgType = 'png';\n\t\t\timagepng($canvas, $tempfile, floor($quality * 0.09));\n\t\t} else if(preg_match('\/^image\/gif$\/i', $mimeType)){\n\t\t\t$imgType = 'gif';\n\t\t\timagegif($canvas, $tempfile);\n\t\t} else {\n\t\t  \t\/\/\u5982\u679c\u4e0d\u662f\u4ee5\u4e0a\u4e09\u79cd\u7c7b\u578b\uff0c\u8bb0\u5f55\u8fd9\u6b21\u9519\u8bef\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\treturn $this->sanityFail(\"Could not match mime type after verifying it previously.\");\n\t\t}\n\t\t\/\/\u4f18\u5148\u4f7f\u7528optipng\u5de5\u5177\u8fdb\u884cpng<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u538b\u7f29\uff0c\u524d\u63d0\u662f\u4f60\u88c5\u4e86\u8fd9\u4e2a\u5de5\u5177\n<\/em><\/em>\t\tif($imgType == 'png' && OPTIPNG_ENABLED && OPTIPNG_PATH && @is_file(OPTIPNG_PATH)){\n\t\t  \t\/\/\u8bb0\u5f55optipng\u7684\u5730\u5740\n<\/em><\/em>\t\t  \t$exec = OPTIPNG_PATH;\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55optipng\u5c06\u8fd0\u884c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t\t$this->debug(3, \"optipng'ing $tempfile\");\n\t\t\t\/\/\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5927\u5c0f\n<\/em><\/em>\t\t\t$presize = filesize($tempfile);\n\t\t\t\/\/\u8fdb\u884c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u538b\u7f29\u64cd\u4f5c\n<\/em><\/em>\t\t\t$out = `$exec -o1 $tempfile`;\n\t\t       \t\/\/\u6e05\u9664\u6587\u4ef6\u72b6\u6001\u7f13\u5b58\t\n<\/em><\/em>\t\t\tclearstatcache();\n\t\t\t\/\/\u83b7\u53d6\u538b\u7f29\u540e\u7684\u6587\u4ef6\u5927\u5c0f\n<\/em><\/em>\t\t\t$aftersize = filesize($tempfile);\n\t\t\t\/\/\u7b97\u51fa\u538b\u7f29\u4e86\u591a\u5927\n<\/em><\/em>\t\t\t$sizeDrop = $presize - $aftersize;\n\t\t\t\/\/\u6839\u636e\u7b97\u51fa\u7684\u4e0d\u540c\u7684\u503c\uff0c\u5199\u65e5\u5fd7\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\tif($sizeDrop > 0){\n\t\t\t\t$this->debug(1, \"optipng reduced size by $sizeDrop\");\n\t\t\t} else if($sizeDrop < 0){\n\t\t\t\t$this->debug(1, \"optipng increased size! Difference was: $sizeDrop\");\n\t\t\t} else {\n\t\t\t\t$this->debug(1, \"optipng did not change image size.\");\n\t\t\t}\n\t\t\/\/optipng\u4e0d\u5b58\u5728\uff0c\u5c31\u5c1d\u8bd5\u4f7f\u7528pngcrush\n<\/em><\/em>\t\t} else if($imgType == 'png' && PNGCRUSH_ENABLED && PNGCRUSH_PATH && @is_file(PNGCRUSH_PATH)){\n\t\t  \t$exec = PNGCRUSH_PATH;\n\t\t\t\/\/\u548coptipng\u4e0d\u540c\u7684\u662f\uff0cpngcrush\u4f1a\u5c06<strong>\u5904\u7406<\/strong>\u5b8c\u7684\u6587\u4ef6\u65b0\u751f\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u6240\u4ee5\u8fd9\u91cc\u65b0\u5efa\u4e2a\u6587\u4ef6\n<\/em><\/em>\t\t\t$tempfile2 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6587\u4ef6\u540d\n<\/em><\/em>\t\t\t$this->debug(3, \"pngcrush'ing $tempfile to $tempfile2\");\n\t\t\t\/\/\u8fd0\u884cpngcrush\n<\/em><\/em>\t\t\t$out = `$exec $tempfile $tempfile2`;\n\t\t\t$todel = \"\";\n\t\t\t\/\/\u5982\u679c\u751f\u6210\u6587\u4ef6\u6210\u529f\n<\/em><\/em>\t\t\tif(is_file($tempfile2)){\n\t\t\t  \t\/\/\u7b97\u51fa\u538b\u7f29\u540e\u7684\u6587\u4ef6\u5927\u5c0f\u7684\u5dee\u503c\n<\/em><\/em>\t\t\t  \t$sizeDrop = filesize($tempfile) - filesize($tempfile2);\n\t\t\t\t\/\/\u5982\u679c\u662f\u4e00\u6b21\u6709\u6548\u7684\u538b\u7f29\uff0c\u5219\u5c06\u538b\u7f29\u540e\u7684\u6587\u4ef6\u4f5c\u4e3a\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\t\tif($sizeDrop > 0){\n\t\t\t\t\t$this->debug(1, \"pngcrush was succesful and gave a $sizeDrop byte size reduction\");\n\t\t\t\t\t$todel = $tempfile;\n\t\t\t\t\t$tempfile = $tempfile2;\n\t\t\t\t\/\/\u5426\u5219\u7684\u8bdd\u5219\u8fd9\u4e2a\u6587\u4ef6\u6ca1\u6709\u5b58\u5728\u7684\u5fc5\u8981\n<\/em><\/em>\t\t\t\t} else {\n\t\t\t\t\t$this->debug(1, \"pngcrush did not reduce file size. Difference was $sizeDrop bytes.\");\n\t\t\t\t\t$todel = $tempfile2;\n\t\t\t\t}\n\t\t\t\/\/\u6ca1\u6709\u8fd0\u884c\u6210\u529f\u4e5f\u9700\u8981\u5220\u9664\u8fd9\u4e2a\u6587\u4ef6\n<\/em><\/em>\t\t\t} else {\n\t\t\t\t$this->debug(3, \"pngcrush failed with output: $out\");\n\t\t\t\t$todel = $tempfile2;\n\t\t\t}\n\t\t\t\/\/\u5220\u9664\u65e0\u6548\u6587\u4ef6\u6216\u538b\u7f29\u524d\u6bd4\u8f83\u5927\u7684\u6587\u4ef6\n<\/em><\/em>\t\t\t@unlink($todel);\n\t\t}\n\t\t\/\/\u5728\u7f13\u5b58<strong><strong>\u56fe\u7247<\/strong><\/strong>\u4e0a\u5199\u5165\u5b89\u5168\u5934\n<\/em><\/em>\t\t$this->debug(3, \"Rewriting image with security header.\");\n\t\t\/\/\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t$tempfile4 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');\n\t\t\/\/\n<\/em><\/em>\t\t$context = stream_context_create ();\n\t\t\/\/\u8bfb\u53d6\u751f\u6210\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7f13\u5b58\u5185\u5bb9\n<\/em><\/em>\t\t$fp = fopen($tempfile,'r',0,$context);\n\t\t\/\/\u5411\u65b0\u7f13\u5b58\u6587\u4ef6\u5199\u5165\u5b89\u5168\u5934\uff0c\u5b89\u5168\u5934\u7684\u957f\u5ea6\u5e94\u8be5\u603b\u662f$this->filePrependSecurityBlock\u7684\u957f\u5ea6 + 6\n<\/em><\/em>\t\tfile_put_contents($tempfile4, $this->filePrependSecurityBlock . $imgType . ' ?' . '>');\n\t\t\/\/\u5c06\u8bfb\u53d6\u51fa\u6765\u7684\u7f13\u5b58<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5185\u5bb9\u5199\u5165\u65b0\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\tfile_put_contents($tempfile4, $fp, FILE_APPEND);\n\t\t\/\/\u5173\u95ed\u6587\u4ef6\u8d44\u6e90\n<\/em><\/em>\t\tfclose($fp);\n\t\t\/\/\u5220\u9664\u4e4b\u524d\u4e0d\u5b89\u5168\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t@unlink($tempfile);\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u7ed9\u7f13\u5b58\u6587\u4ef6\u52a0\u9501\uff5e\uff5e\n<\/em><\/em>\t\t$this->debug(3, \"Locking and replacing cache file.\");\n\t\t\/\/\u521b\u5efa\u9501\u6587\u4ef6\u6587\u4ef6\u540d\n<\/em><\/em>\t\t$lockFile = $this->cachefile . '.lock';\n\t\t\/\/\u521b\u5efa\u6216\u6253\u5f00\u9501\u6587\u4ef6\n<\/em><\/em>\t\t$fh = fopen($lockFile, 'w');\n\t\t\/\/\u521b\u5efa\u5931\u8d25\u76f4\u63a5\u9000\u51fa\n<\/em><\/em>\t\tif(! $fh){\n\t\t\treturn $this->error(\"Could not open the lockfile for writing an image.\");\n\t\t}\n\t\t\/\/\u5982\u679c\u7ed9\u9501\u6587\u4ef6\u52a0\u5165\u5199\u5165\u9501\u6210\u529f\n<\/em><\/em>\t\tif(flock($fh, LOCK_EX)){\n\t\t  \t\/\/\u5220\u9664\u539f\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t  \t@unlink($this->cachefile); \n\t\t\t\/\/\u91cd\u547d\u540d\u8986\u76d6\uff0c\u5c06\u5b89\u5168\u7684\u7f13\u5b58\u6587\u4ef6\u4f5c\u4e3a\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\trename($tempfile4, $this->cachefile);\n\t\t\t\/\/\u91ca\u653e\u5199\u5165\u9501\n<\/em><\/em>\t\t\tflock($fh, LOCK_UN);\n\t\t\t\/\/\u91ca\u653e\u8d44\u6e90\n<\/em><\/em>\t\t\tfclose($fh);\n\t\t\t\/\/\u5220\u9664\u9501\u6587\u4ef6\n<\/em><\/em>\t\t\t@unlink($lockFile);\n\t\t\/\/\u5426\u5219\n<\/em><\/em>\t\t} else {\n\t\t  \t\/\/\u5173\u95ed\u8d44\u6e90\n<\/em><\/em>\t\t  \tfclose($fh);\n\t\t\t\/\/\u5220\u9664\u9501\u6587\u4ef6\n<\/em><\/em>\t\t\t@unlink($lockFile);\n\t\t\t\/\/\u5220\u9664\u5b89\u5168\u7684\u7f13\u5b58\u6587\u4ef6\n<\/em><\/em>\t\t\t@unlink($tempfile4);\n\t\t\t\/\/\u8bb0\u5f55\u9519\u8bef\u5e76\u9000\u51fa\n<\/em><\/em>\t\t\treturn $this->error(\"Could not get a lock for writing.\");\n\t\t}\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u64cd\u4f5c\u5b8c\u6210\n<\/em><\/em>\t\t$this->debug(3, \"Done image replace with security header. Cleaning up and running cleanCache()\");\n\t\t\/\/\u91ca\u653e<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8d44\u6e90\n<\/em><\/em>\t\timagedestroy($canvas);\n\t\timagedestroy($image);\n\t\t\/\/\u751f\u6210\u7f13\u5b58\u6210\u529f\u8fd4\u56de\u771f\n<\/em><\/em>\t\treturn true;\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u83b7\u53d6\u670d\u52a1\u5668\u6587\u6863\u6839\u76ee\u5f55*\/<\/em>\n\tprotected function calcDocRoot(){\n\t  \t\/\/\u76f4\u63a5\u83b7\u53d6\u6587\u6863\u6839\u76ee\u5f55\n<\/em><\/em>\t  \t$docRoot = @$_SERVER['DOCUMENT_ROOT'];\n\t\t\/\/\u5982\u679c\u5b9a\u4e49\u4e86LOCAL_FILE_BASE_DIRECTORY\uff0c\u5219\u4f7f\u7528\u6b64\u503c\n<\/em><\/em>\t\tif (defined('LOCAL_FILE_BASE_DIRECTORY')) {\n\t\t\t$docRoot = LOCAL_FILE_BASE_DIRECTORY;   \n\t\t}\n\t\t\/\/\u5982\u679c\u6ca1\u6709\u83b7\u53d6\u5230\u6587\u6863\u6839\u76ee\u5f55\uff0c\u4e5f\u5c31\u662fDOCUMENT_ROOT\u7684\u503c\n<\/em><\/em>\t\tif(!isset($docRoot)){\n\t\t  \t\/\/\u5199\u4e00\u6761\u8bb0\u5f55\uff0c\u8bf4\u660eDOCUMENT_ROOT\u6ca1\u627e\u5230\uff0c\u6ce8\u610flevel\u662f3\n<\/em><\/em>\t\t  \t$this->debug(3, \"DOCUMENT_ROOT is not set. This is probably windows. Starting search 1.\");\n\t\t\t\/\/\u7528SCRIPT_FILENAME\u548cPHP_SELF\u6765\u5f97\u5230\u6587\u6863\u6839\u76ee\u5f55\n<\/em><\/em>\t\t\tif(isset($_SERVER['SCRIPT_FILENAME'])){\n\t\t\t  \t$docRoot = str_replace( '\\', '\/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));\n\t\t\t\t\/\/\u5199\u4e00\u6761\u8bb0\u5f55\uff0c\u8bf4\u660eDOCUMENT_ROOT\u7684\u503c\u662f\u901a\u8fc7SCRIPT_FILENAME\u548cPHP_SELF\u6765\u5f97\u7684\uff0c\u7ea7\u522b3\n\t\t\t\t$this->debug(3, \"Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: $docRoot\");\n\t\t\t} \n\t\t}\n\t\t\/\/\u5982\u679c\u8fd8\u662f\u6ca1\u6709\u83b7\u53d6\u5230\u6587\u6863\u6839\u76ee\u5f55\n\t\tif(!isset($docRoot)){\n\t\t  \t\/\/\u5148\u5199\u4e00\u6761\u8bb0\u5f55\uff0c\u8bf4\u660e\u8fd8\u662f\u6ca1\u5f97\u5230DOCUMENT_ROOT\uff0c\u7ea7\u522b3\n\t\t  \t$this->debug(3, \"DOCUMENT_ROOT still is not set. Starting search 2.\");\n\t\t\t\/\/\u901a\u8fc7PATH_TRANSLATED\u548cPHP_SELF\u6765\u5f97\u5230\u6587\u6863\u6839\u76ee\u5f55\uff0c\u5173\u4e8ePATH_TRANSLATED\u7684\u8bf4\u660e\u53ef\u4ee5\u770b\u8fd9\u91cc\uff1ahttp:\/\/blogs.msdn.com\/b\/david.wang\/archive\/2005\/08\/04\/what-is-path-translated.aspx\n\t\t\tif(isset($_SERVER['PATH_TRANSLATED'])){\n\t\t\t  \t$docRoot = str_replace( '\\', '\/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));\n\t\t\t\t\/\/\u5199\u8bb0\u5f55\uff0c\u8bf4\u660e\u8bf4\u660eDOCUMENT_ROOT\u7684\u503c\u662f\u901a\u8fc7PATH_TRANSLATED\u548cPHP_SELF\u6765\u5f97\u7684\uff0c\u7ea7\u522b3\n\t\t\t\t$this->debug(3, \"Generated docRoot using PATH_TRANSLATED and PHP_SELF as: $docRoot\");\n\t\t\t} \n\t\t}\n\t\t\/\/\u5982\u679c\u6587\u6863\u6839\u76ee\u5f55\u4e0d\u662f\u670d\u52a1\u5668\u6839\u76ee\u5f55\uff0c\u5219\u53bb\u6389\u6700\u540e\u4e00\u4e2a '\/'\n\t\tif($docRoot && $_SERVER['DOCUMENT_ROOT'] != '\/'){ $docRoot = preg_replace('\/\/$\/', '', $docRoot); }\n<\/em><\/em>\t\t\/\/\u5199\u8bb0\u5f55\uff0c\u8bf4\u660e\u6587\u6863\u6839\u76ee\u5f55\u7684\u503c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t$this->debug(3, \"Doc root is: \" . $docRoot);\n\t\t\/\/\u8d4b\u503c\u7ed9\u6210\u5458\u5c5e\u6027\n<\/em><\/em>\t\t$this->docRoot = $docRoot;\n\n\t}\n\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u83b7\u53d6\u672c\u5730<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\uff0c\u53c2\u6570src\u662f\u76f8\u5bf9\u4e0e\u6587\u6863\u6839\u76ee\u5f55\u7684\u5730\u5740*\/<\/em>\n\tprotected function getLocalImagePath($src){\n\t  \t\/\/\u53bb\u6389\u5f00\u5934\u7684 \/ \n<\/em><\/em>\t \t $src = ltrim($src, '\/');\n\t\t \/\/\u5982\u679c\u524d\u9762\u6ca1\u6709\u83b7\u53d6\u5230\u6587\u6863\u6839\u76ee\u5f55\uff0c\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0c\u90a3\u4e48\u8fd9\u91cc\u53ea\u80fd\u5bf9timthumbs.php\u6240\u5728\u7684\u76ee\u5f55\u4e0b\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8fdb\u884c\u64cd\u4f5c\n<\/em><\/em>\t\t if(! $this->docRoot){\n\t\t   \t\/\/\u5199\u65e5\u5fd7\uff0c\u7ea7\u522b3\uff0c\u8bf4\u660e\u4e0b\u9762\u8fdb\u884c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\u7684\u68c0\u67e5\n<\/em><\/em>\t\t\t$this->debug(3, \"We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that.\");\n\t\t\t\/\/\u83b7\u53d6\u53bb\u6389\u6240\u6709\u8def\u5f84\u4fe1\u606f\u7684\u6587\u4ef6\u540d\n<\/em><\/em>\t\t\t$file = preg_replace('\/^.*?([^\/\\\\]+)$\/', '$1', $src); \n\t\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6587\u4ef6\u548ctimthumb.php\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\n<\/em><\/em>\t\t\tif(is_file($file)){\n\t\t\t  \t\/\/\u8fd4\u56de\u6b64<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u8def\u5f84\n<\/em><\/em>\t\t\t\treturn $this->realpath($file);\n\t\t\t}\n\t\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6587\u4ef6\u548ctimthumb.php\u4e0d\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff0c\u5199\u9519\u8bef\u4fe1\u606f\uff0c\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0c\u4e0d\u4f1a\u5141\u8bb8\u4e00\u4e2a\u6ca1\u6709\u6587\u6863\u6839\u76ee\u5f55\u5e76\u4e14\u5728timthumbs.php\u6240\u5728\u7684\u76ee\u5f55\u4ee5\u5916\u7684\u6587\u4ef6\n<\/em><\/em>\t\t\treturn $this->error(\"Could not find your website document root and the file specified doesn't exist in timthumbs directory. We don't support serving files outside timthumb's directory without a document root for security reasons.\");\n\t\t}\n\n\t\t \/\/\u5c1d\u8bd5\u627e\u8fd9\u5f20<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\u5b58\u5728\n<\/em><\/em>\t\t if(file_exists ($this->docRoot . '\/' . $src)) {\n\t\t   \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6587\u4ef6\u5730\u5740\uff0c\u7ea7\u522b3\n<\/em><\/em>\t\t   \t$this->debug(3, \"Found file as \" . $this->docRoot . '\/' . $src);\n\t\t\t\/\/\u8fd4\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8def\u5f84\n<\/em><\/em>\t\t\t$real = $this->realpath($this->docRoot . '\/' . $src);\n\t\t\t\/\/\u9a8c\u8bc1<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8def\u5f84\u662f\u5426\u5728\u672c\u673a\n<\/em><\/em>\t\t\tif(stripos($real, $this->docRoot) === 0){\n\t\t\t  \t\/\/\u662f\u7684\u8bdd\u8fd4\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740\n<\/em><\/em>\t\t\t\treturn $real;\n\t\t\t} else {\n\t\t\t  \t\/\/\u5426\u5219\u5199\u65e5\u5fd7\uff0c\u6ca1\u627e\u5230\u6307\u5b9a\u6587\u4ef6\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\t\t$this->debug(1, \"Security block: The file specified occurs outside the document root.\");\n\t\t\t}\n\t\t}\n\n\t\t\/\/\u63a5\u7740\u627e\u3002\u3002\u3002\n<\/em><\/em>\t\t $absolute = $this->realpath('\/' . $src);\n\t\t \/\/\u5982\u679c\u51b3\u5b9a\u5730\u5740\u5b58\u5728\n<\/em><\/em>\t\t if($absolute && file_exists($absolute)){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7edd\u5bf9\u5730\u5740\uff0c\u7ea7\u522b3 \n<\/em><\/em>\t\t   \t$this->debug(3, \"Found absolute path: $absolute\");\n\t\t\t\/\/\u5982\u679c\u6587\u6863\u6839\u76ee\u5f55\u6ca1\u6709\u5b9a\u4e49\uff0c\u8bb0\u5f55\u8fd9\u4e2a\u9519\u8bef\u4fe1\u606f\n<\/em><\/em>\t\t\tif(! $this->docRoot){ $this->sanityFail(\"docRoot not set when checking absolute path.\"); }\n\t\t\t\/\/\u9a8c\u8bc1<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8def\u5f84\u662f\u5426\u5728\u672c\u673a\n<\/em><\/em>\t\t\tif(stripos($absolute, $this->docRoot) === 0){\n\t\t\t\t\/\/\u5728\u7684\u8bdd\u8fd4\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5730\u5740    \n<\/em><\/em>\t\t\t\treturn $absolute;\n\t\t\t} else {\n\t\t\t  \t\/\/\u5426\u5219\u5199\u65e5\u5fd7\uff0c\u6ca1\u627e\u5230\u6307\u5b9a\u7684\u6587\u4ef6\uff0c\u7ea7\u522b1\n<\/em><\/em>\t\t\t\t$this->debug(1, \"Security block: The file specified occurs outside the document root.\");\n\t\t\t}\n\t\t}\n\n\t\t\/\/\u5982\u679c\u8fd8\u6ca1\u627e\u5230\u6307\u5b9a\u6587\u4ef6\uff0c\u5219\u9010\u7ea7\u5411\u4e0a\u67e5\u627e\n<\/em><\/em>\t\t$base = $this->docRoot;\n\t\t\n\t\t\/\/ \u83b7\u53d6\u67e5\u8be2\u5b50\u76ee\u5f55\u5217\u8868\n<\/em><\/em>\t\tif (strstr($_SERVER['SCRIPT_FILENAME'],':')) {\n\t\t\t$sub_directories = explode('\\', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));\n\t\t} else {\n\t\t\t$sub_directories = explode('\/', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));\n\t\t}\n\t\t\/\/\u904d\u5386\u5b50\u76ee\u5f55\u6570\u7ec4\n\t\tforeach ($sub_directories as $sub){\n\t\t  \t\/\/\u91cd\u65b0\u7ec4\u5408\u8bf7\u6c42\u5730\u5740\n\t\t  \t$base .= $sub . '\/';\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u641c\u7d22\u8bb0\u5f55\uff0c\u7ea7\u522b3\n\t\t\t$this->debug(3, \"Trying file as: \" . $base . $src);\n\t\t\t\/\/\u5982\u679c\u627e\u5230\u4e86\u8fd9\u4e2a\u6587\u4ef6\n\t\t\tif(file_exists($base . $src)){\n\t\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6587\u4ef6\u5730\u5740\uff0c\u7ea7\u522b3\n\t\t\t  \t$this->debug(3, \"Found file as: \" . $base . $src);\n\t\t\t\t\/\/\u5f97\u5230\u5b9e\u9645\u5730\u5740\n\t\t\t\t$real = $this->realpath($base . $src);\n\t\t\t\t\/\/\u5982\u679c\u5b9e\u9645\u5730\u5740\u7684\u786e\u5728\u672c\u673a\u4e2d\uff0c\u90a3\u4e48\u8fd4\u56de\u8fd9\u4e2a\u5730\u5740\n\t\t\t\tif(stripos($real, $this->realpath($this->docRoot)) === 0){\n\t\t\t\t\treturn $real;\n\t\t\t\t} else {\n\t\t\t\t  \t\/\/\u627e\u4e0d\u5230\u5c31\u5199\u65e5\u5fd7\uff0c\u6ca1\u627e\u5230,\u7ea7\u522b1\n\t\t\t\t\t$this->debug(1, \"Security block: The file specified occurs outside the document root.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\/\/\u8fd8\u627e\u4e0d\u5230\u7684\u8bdd\uff0c\u5c31\u8fd4\u56defalse;\n\t\treturn false;\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u83b7\u5f97\u4f20\u5165\u6587\u4ef6\u53c2\u6570\u7684\u771f\u5b9e\u8def\u5f84*\/\n\tprotected function realpath($path){\n\t\t\/\/\u53bb\u9664\u8def\u5f84\u4e2d\u5e26\u6709..\u7684\u76f8\u5bf9\u8def\u5f84\n\t\t$remove_relatives = '\/w+\/..\/\/';\n\t\twhile(preg_match($remove_relatives,$path)){\n\t\t    $path = preg_replace($remove_relatives, '', $path);\n\t\t}\n\t\t\/\/\u5982\u679c\u53bb\u9664\u540e\u8def\u5f84\u4e2d\u4ecd\u6709..\u7684\u76f8\u5bf9\u8def\u5f84\uff0c\u5219\u7528realpath\u51fd\u6570\u8fd4\u56de\u8def\u5f84\uff0c\u5426\u5219\u76f4\u63a5\u8fd4\u56de\u5373\u53ef\n\t\treturn preg_match('#^..\/|\/..\/#', $path) ? realpath($path) : $path;\n<\/em><\/em>\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8bb0\u5f55\u5728\u6790\u6784\u51fd\u6570\u4e2d\u9700\u8981\u5220\u9664\u7684\u8d44\u6e90\u5217\u8868*\/<\/em>\n\tprotected function toDelete($name){\n\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u9700\u8981\u5220\u9664\u7684\u6587\u4ef6\u4fe1\u606f\n<\/em><\/em>\t  \t$this->debug(3, \"Scheduling file $name to delete on destruct.\");\n\t\t\/\/\u6dfb\u52a0\u5230\u5f85\u5220\u9664\u6570\u7ec4\n<\/em><\/em>\t\t$this->toDeletes[] = $name;\n\t}\n\t\/*\u6b64\u51fd\u6570\u662f\u622a\u56fe\u64cd\u4f5c\u7684\u5177\u4f53\u5b9e\u73b0*\/<\/em>\n\tprotected function serveWebshot(){\n\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u5f00\u59cb\u622a\u56fe\u64cd\u4f5c\uff0c\u7ea7\u522b3\n<\/em><\/em>\t  \t$this->debug(3, \"Starting serveWebshot\");\n\t\t\/\/\u4e00\u6bb5\u63d0\u793a\u6587\u5b57\uff0c\u53ef\u4ee5\u5230http:\/\/code.google.com\/p\/timthumb\/\u4e0a\u6309\u7167\u6559\u7a0b\u8fdb\u884c\u7f51\u7ad9\u622a\u56fe\u8bbe\u7f6e\n<\/em><\/em>\t\t$instr = \"Please follow the instructions at http:\/\/code.google.com\/p\/timthumb\/ to set your server up for taking website screenshots.\";\n\t\t\/\/\u5982\u679cCutyCapt\u4e0d\u5b58\u5728\n<\/em><\/em>\t\tif(! is_file(WEBSHOT_CUTYCAPT)){\n\t\t  \t\/\/\u9000\u51fa\u6267\u884c\u5e76\u8bb0\u5f55\uff0cCutyCapt\u672a\u88ab\u5b89\u88c5\n<\/em><\/em>\t\t\treturn $this->error(\"CutyCapt is not installed. $instr\");\n\t\t}\n\t\t\/\/\u5982\u679cxvfb\u4e0d\u5b58\u5728\n<\/em><\/em>\t\tif(! is_file(WEBSHOT_XVFB)){\n\t\t  \t\/\/\u9000\u51fa\u6267\u884c\u5e76\u8bb0\u5f55\uff0cxvfb\u672a\u88ab\u5b89\u88c5\n<\/em><\/em>\t\t\treturn $this->Error(\"Xvfb is not installed. $instr\");\n\t\t}\n\t\t\/\/CUTYCAPT\u5730\u5740\n<\/em><\/em>\t\t$cuty = WEBSHOT_CUTYCAPT;\n\t\t\/\/xvfb\u5730\u5740\n<\/em><\/em>\t\t$xv = WEBSHOT_XVFB;\n\t\t\/\/\u622a\u56fe\u5c4f\u5e55\u5bbd\u5ea6\n<\/em><\/em>\t\t$screenX = WEBSHOT_SCREEN_X;\n\t\t\/\/\u622a\u56fe\u5c4f\u5e55\u9ad8\u5ea6\n<\/em><\/em>\t\t$screenY = WEBSHOT_SCREEN_Y;\n\t\t\/\/\u622a\u56fe\u8272\u6df1\n<\/em><\/em>\t\t$colDepth = WEBSHOT_COLOR_DEPTH;\n\t\t\/\/\u622a\u56fe\u4fdd\u5b58\u683c\u5f0f\n<\/em><\/em>\t\t$format = WEBSHOT_IMAGE_FORMAT;\n\t\t\/\/\u622a\u56fe\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4dms\n<\/em><\/em>\t\t$timeout = WEBSHOT_TIMEOUT * 1000;\n\t\t\/\/USER_AGENT\u5934\n<\/em><\/em>\t\t$ua = WEBSHOT_USER_AGENT;\n\t\t\/\/\u662f\u5426\u542f\u7528js\n<\/em><\/em>\t\t$jsOn = WEBSHOT_JAVASCRIPT_ON ? 'on' : 'off';\n\t\t\/\/\u662f\u5426\u542f\u7528java\n<\/em><\/em>\t\t$javaOn = WEBSHOT_JAVA_ON ? 'on' : 'off';\n\t\t\/\/\u662f\u5426\u542f\u7528\u5176\u4ed6\u63d2\u4ef6\n<\/em><\/em>\t\t$pluginsOn = WEBSHOT_PLUGINS_ON ? 'on' : 'off';\n\t\t\/\/\u662f\u5426\u542f\u7528\u4ee3\u7406\n<\/em><\/em>\t\t$proxy = WEBSHOT_PROXY ? ' --http-proxy=' . WEBSHOT_PROXY : '';\n\t\t\/\/\u5728\u7f13\u5b58\u6587\u4ef6\u76ee\u5f55\uff0c\u5efa\u7acb\u4e00\u4e2a\u5177\u6709\u552f\u4e00\u6587\u4ef6\u540d\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u524d\u7f00\u4e3atimthumb_webshot\uff0c\u7528\u6237\u5b58\u50a8\u622a\u56fe\u540e\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t$tempfile = tempnam($this->cacheDirectory, 'timthumb_webshot');\n\t\t\/\/\u76ee\u6807\u7f51\u7ad9\u5730\u5740\n<\/em><\/em>\t\t$url = $this->src;\n\t\t\/\/\u9a8c\u8bc1url\u5408\u6cd5\u6027\n<\/em><\/em>\t\tif(! preg_match('\/^http?:\/\/[a-zA-Z0-9.-]+\/i', $url)){\n\t\t  \t\/\/\u4e0d\u5408\u6cd5\u9000\u51fa\u6267\u884c\n<\/em><\/em>\t\t\treturn $this->error(\"Invalid URL supplied.\");\n\t\t}\n\t\t\/\/\u8fc7\u6ee4\u6389\u975e\u6cd5\u5b57\u7b26\n<\/em><\/em>\t\t$url = preg_replace('\/[^A-Za-z0-9-._~:\/?#[]@!$&'()*+,;=]+\/', '', $url);\n\t\t\/\/\u4f18\u5148\u4f7f\u7528CUTYCAPT\n\t\tif(WEBSHOT_XVFB_RUNNING){\n\t\t  \t\/\/\u8bbe\u7f6e\u7cfb\u7edf\u53d8\u91cf\uff0c\u914d\u7f6e\u56fe\u5f62\u8f93\u51fa\u663e\u793a\u3002\n\t\t  \tputenv('DISPLAY=:100.0');\n\t\t\t\/\/\u7ec4\u88c5shell\u547d\u4ee4\n\t\t\t$command = \"$cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile\";\n\t\t\/\/\u5426\u5219\u4f7f\u7528XVFB\n\t\t} else {\n\t\t\t$command = \"$xv --server-args=\"-screen 0, {$screenX}x{$screenY}x{$colDepth}\" $cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile\";\n\t\t}\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6267\u884c\u7684\u547d\u4ee4\uff0c\u7ea7\u522b3\n\t\t$this->debug(3, \"Executing command: $command\");\n\t\t\/\/\u6267\u884c\u547d\u4ee4\u5e76\u6355\u83b7\u8f93\u51fa\n\t\t$out = `$command`;\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8f93\u51fa\uff0c\u7ea7\u522b3\n\t\t$this->debug(3, \"Received output: $out\");\n\t\t\/\/\u5982\u679c\u521a\u521a\u521b\u5efa\u7684\u552f\u4e00\u6587\u4ef6\u540d\u7684\u6587\u4ef6\u5931\u8d25\n\t\tif(! is_file($tempfile)){\n\t\t  \t\/\/\u8bbe\u7f6e404\u9519\u8bef\n\t\t  \t$this->set404();\n\t\t  \t\/\/\u63a8\u51fa\u811a\u672c\n\t\t\treturn $this->error(\"The command to create a thumbnail failed.\");\n\t\t}\n\t\t\/\/\u542f\u7528\u88c1\u526a\n\t\t$this->cropTop = true;\n\t\t\/\/\u5bf9\u622a\u53d6\u5230\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6587\u4ef6<strong>\u5904\u7406<\/strong>\u5e76\u751f\u6210\u7f13\u5b58\n\t\tif($this->processImageAndWriteToCache($tempfile)){\n\t\t  \t\/\/\u6210\u529f\u7684\u8bdd\u5199\u65e5\u5fd7\uff0c\u5e76\u4ece\u7f13\u5b58\u8bfb\u53d6\u6b64<strong><strong>\u56fe\u7247<\/strong><\/strong>\n\t\t  \t$this->debug(3, \"Image processed succesfully. Serving from cache\");\n\t\t\t\/\/\u8fd4\u56de\u4ece\u7f13\u5b58\u4e2d\u8bfb\u53d6\u7684\u6587\u4ef6\u5185\u5bb9\n\t\t\treturn $this->serveCacheFile();\n\t\t\/\/\u6ca1\u6210\u529f\u5c31\u8fd4\u56de\u5047\u54af\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u4ece\u5916\u90e8url\u83b7\u53d6\u56fe\u50cf*\/\n\tprotected function serveExternalImage(){\n\t  \t\/\/\u9a8c\u8bc1url\u5408\u6cd5\u6027\n\t\tif(! preg_match('\/^http?:\/\/[a-zA-Z0-9-.]+\/i', $this->src)){\n\t\t\t$this->error(\"Invalid URL supplied.\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u751f\u6210\u4e34\u65f6\u7f13\u5b58\u6587\u4ef6\n\t\t$tempfile = tempnam($this->cacheDirectory, 'timthumb');\n\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8bfb\u53d6\u5916\u90e8\u56fe\u50cf\u5230\u4e34\u65f6\u6587\u4ef6\uff0c\u7ea7\u522b3\n\t\t$this->debug(3, \"Fetching external image into temporary file $tempfile\");\n\t\t\/\/\u5c06\u4e34\u65f6\u7f13\u5b58\u6587\u4ef6\u52a0\u5165\u5230\u5f85\u5220\u9664\u5217\u8868\n\t\t$this->toDelete($tempfile);\n\t\t\/\/\u8bf7\u6c42url\u5e76\u5c06\u7ed3\u679c\u5199\u5165\u5230\u4e34\u65f6\u7f13\u5b58\u6587\u4ef6\u4e2d\uff0c\u5982\u679c\u6ca1\u6709\u6210\u529f\n\t\tif(! $this->getURL($this->src, $tempfile)){\n\t\t  \t\/\/\u5220\u9664\u6b64\u7f13\u5b58\u6587\u4ef6\n\t\t  \t@unlink($this->cachefile);\n\t\t\t\/\/\u518d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7f13\u5b58\u6587\u4ef6\n\t\t\ttouch($this->cachefile);\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\uff0c\u7ea7\u522b3\n\t\t\t$this->debug(3, \"Error fetching URL: \" . $this->lastURLError);\n\t\t\t\/\/\u5199\u9519\u8bef\u4fe1\u606f\uff0c\u5e76\u9000\u51fa\n\t\t\t$this->error(\"Error reading the URL you specified from remote host.\" . $this->lastURLError);\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u5f97\u5230\u83b7\u53d6\u5230<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684MIME\u7c7b\u578b\n\t\t$mimeType = $this->getMimeType($tempfile);\n\t\t\/\/\u5982\u679c\u4e0d\u5728\u8fd9\u4e09\u79cd\u7c7b\u578b\u4e2d\n\t\tif(! preg_match(\"\/^image\/(?:jpg|jpeg|gif|png)$\/i\", $mimeType)){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\uff0c\u7ea7\u522b3\n\t\t  \t$this->debug(3, \"Remote file has invalid mime type: $mimeType\");\n\t\t\t\/\/\u5220\u9664\u73b0\u6709\u7f13\u5b58\u6587\u4ef6\n\t\t\t@unlink($this->cachefile);\n\t\t\t\/\/\u521b\u5efa\u65b0\u7f13\u5b58\u6587\u4ef6\n\t\t\ttouch($this->cachefile);\n\t\t\t\/\/\u5199\u9519\u8bef\u4fe1\u606f\u5e76\u9000\u51fa\n\t\t\t$this->error(\"The remote file is not a valid image.\");\n\t\t\treturn false;\n\t\t}\n\t\t\/\/<strong>\u5904\u7406<\/strong>\u56fe\u50cf\u5e76\u7f13\u5b58\n\t\tif($this->processImageAndWriteToCache($tempfile)){\n\t\t  \t$this->debug(3, \"Image processed succesfully. Serving from cache\");\n\t\t  \t\/\/\u6210\u529f\u7684\u8bdd\u8fd4\u56de\u7f13\u5b58\u4fe1\u606f\n\t\t\treturn $this->serveCacheFile();\n\t\t} else {\n\t\t  \t\/\/\u5931\u8d25\u8fd4\u56de\u5047\n\t\t\treturn false;\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u5c06curl\u83b7\u53d6\u5230\u7684\u6570\u636e\u5199\u5165\u5bf9\u5e94\u6587\u4ef6\u4e2d*\/\n\tpublic static function curlWrite($h, $d){\n\t  \t\/\/\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\n\t  \tfwrite(self::$curlFH, $d);\n\t\t\/\/\u8bb0\u5f55\u6570\u636e\u957f\u5ea6\n\t\tself::$curlDataWritten += strlen($d);\n\t\t\/\/\u5982\u679c<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5927\u5c0f\u8d85\u8fc7\u4e86\u914d\u7f6e\u6587\u4ef6\u7684\u9650\u5236\uff0c\u5219\u8fd4\u56de0\n\t\tif(self::$curlDataWritten > MAX_FILE_SIZE){\n\t\t  \treturn 0;\n\t\t\/\/\u5426\u5219\u8fd4\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5927\u5c0f\n\t\t} else {\n\t\t\treturn strlen($d);\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8bfb\u53d6\u5e76\u8f93\u51fa\u670d\u52a1\u7aef\u7f13\u5b58*\/\n\tprotected function serveCacheFile(){\n\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8bfb\u53d6\u7f13\u5b58\u7684\u5730\u5740\n\t  \t$this->debug(3, \"Serving {$this->cachefile}\");\n\t\t\/\/\u5982\u679c\u7f13\u5b58\u5730\u5740\u65e0\u6548\n\t\tif(! is_file($this->cachefile)){\n\t\t  \t\/\/\u6dfb\u52a0\u5230\u9519\u8bef\u8bb0\u5f55\n\t\t  \t$this->error(\"serveCacheFile called in timthumb but we couldn't find the cached file.\");\n\t\t\t\/\/\u505c\u6b62\u6267\u884c\u811a\u672c\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u7f13\u5b58\u5730\u5740\u6709\u6548\u7684\u8bdd\uff0c\u5df2\u53ea\u8bfb\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6\n\t\t$fp = fopen($this->cachefile, 'rb');\n\t\t\/\/\u5982\u679c\u6253\u5f00\u5931\u8d25\uff0c\u76f4\u63a5\u9000\u51fa\u811a\u672c\uff0c\u5e76\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n\t\tif(! $fp){ return $this->error(\"Could not open cachefile.\"); }\n\t\t\/\/\u8bbe\u5b9a\u6587\u4ef6\u6307\u9488\u8df3\u8fc7filePrependSecurityBlock\u503c\uff0c\u4e5f\u5c31\u662f\u8df3\u8fc7\u5b89\u5168\u5934\u540e\u5f00\u59cb\u8bfb\n\t\tfseek($fp, strlen($this->filePrependSecurityBlock), SEEK_SET);\n\t\t\/\/\u8bfb\u51fa\u6587\u4ef6\u7684mime\u7c7b\u578b\n\t\t$imgType = fread($fp, 3);\n\t\t\/\/\u518d\u8df3\u8fc7\u8fd9\u4e2amime\u7c7b\u578b\u7684\u503c\n\t\tfseek($fp, 3, SEEK_CUR);\n\t\t\/\/\u5982\u679c\u73b0\u5728\u6587\u4ef6\u7684\u6307\u9488\u4e0d\u662f\u5728\u5b89\u5168\u5934\u540e6\u4e2a\u5b57\u7b26\u7684\u4f4d\u7f6e\uff0c\u8bf4\u660e\u7f13\u5b58\u6587\u4ef6\u53ef\u80fd\u5df2\u635f\u574f\n\t\tif(ftell($fp) != strlen($this->filePrependSecurityBlock) + 6){\n\t\t  \t\/\/\u5220\u9664\u6b64\u7f13\u5b58\u6587\u4ef6\n\t\t  \t@unlink($this->cachefile);\n\t\t\t\/\/\u8bb0\u5f55\u9519\u8bef\u5e76\u9000\u51fa\u6267\u884c\n\t\t\treturn $this->error(\"The cached image file seems to be corrupt.\");\n\t\t}\n\t\t\/\/\u7f13\u5b58<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684\u5b9e\u9645\u5927\u5c0f\u5e94\u8be5\u662f\u6587\u4ef6\u5927\u5c0f - \u5b89\u5168\u5934\u5927\u5c0f\n\t\t$imageDataSize = filesize($this->cachefile) - (strlen($this->filePrependSecurityBlock) + 6);\n\t\t\/\/\u8bbe\u7f6e\u8f93\u51fa\u5fc5\u8981\u7684HTTP\u5934\n\t\t$this->sendImageHeaders($imgType, $imageDataSize);\n\t\t\/\/\u8f93\u51fa\u6587\u4ef6\u6307\u9488\u5904\u6240\u6709\u5269\u4f59\u6570\u636e\n\t\t$bytesSent = @fpassthru($fp);\n\t\t\/\/\u5173\u95ed\u6587\u4ef6\u8d44\u6e90\n\t\tfclose($fp);\n\t\t\/\/\u5982\u679c\u6b64\u65b9\u6cd5\u6267\u884c\u6210\u529f\uff0c\u5219\u8fd4\u56de\u771f\n\t\tif($bytesSent > 0){\n\t\t\treturn true;\n\t\t}\n\t\t\/\/\u5982\u679cfpassthru\u4e0d\u6210\u529f\uff0c\u5219\u7528file_get_contents\u8bfb\u53d6\u5e76\u8f93\u51fa\n\t\t$content = file_get_contents ($this->cachefile);\n\t\t\/\/\u5982\u679c\u8bfb\u53d6\u6210\u529f\n\t\tif ($content != FALSE) {\n\t\t  \t\/\/\u622a\u53d6\u6389\u5b89\u5168\u5934\n\t\t  \t$content = substr($content, strlen($this->filePrependSecurityBlock) + 6);\n\t\t\t\/\/\u8f93\u51fa\u56fe\u50cf\n\t\t\techo $content;\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8bfb\u53d6\u7f13\u5b58\u7684\u65b9\u5f0f\n\t\t\t$this->debug(3, \"Served using file_get_contents and echo\");\n\t\t\treturn true;\n\t\t\/\/\u8bfb\u53d6\u5931\u8d25\u7684\u8bdd\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u5e76\u9000\u51fa\u6267\u884c\n\t\t} else {\n\t\t\t$this->error(\"Cache file could not be loaded.\");\n\t\t\treturn false;\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u8bbe\u7f6e<strong><strong>\u56fe\u7247<\/strong><\/strong>\u8f93\u51fa\u5fc5\u8981\u7684http\u5934*\/\n\tprotected function sendImageHeaders($mimeType, $dataSize){\n\t  \t\/\/\u8865\u5168<strong><strong>\u56fe\u7247<\/strong><\/strong>\u7684mime\u4fe1\u606f\n\t\tif(! preg_match('\/^image\/\/i', $mimeType)){\n\t\t\t$mimeType = 'image\/' . $mimeType;\n\t\t}\n\t\t\/\/\u5c06jpg\u7684mime\u7c7b\u578b\u5199\u6807\u51c6\uff0c\u8fd9\u91cc\u4e0d\u6807\u51c6\u7684\u539f\u56e0\u662f\u5728\u9a8c\u8bc1\u6587\u4ef6\u5b89\u5168\u5934\u65f6\u8ffd\u6c42\u4e86\u4fbf\u5229\u6027\n\t\tif(strtolower($mimeType) == 'image\/jpg'){\n\t\t\t$mimeType = 'image\/jpeg';\n\t\t}\n\t\t\/\/\u6d4f\u89c8\u5668\u7f13\u5b58\u5931\u6548\u65f6\u95f4\n\t\t$gmdate_expires = gmdate ('D, d M Y H:i:s', strtotime ('now +10 days')) . ' GMT';\n\t\t\/\/\u6587\u6863\u6700\u540e\u88ab\u4fee\u6539\u65f6\u95f4\uff0c\u7528\u6765\u8ba9\u6d4f\u89c8\u5668\u5224\u65ad\u662f\u5426\u9700\u8981\u91cd\u65b0\u8bf7\u6c42\u9875\u9762\n\t\t$gmdate_modified = gmdate ('D, d M Y H:i:s') . ' GMT';\n\t\t\/\/ \u8bbe\u7f6eHTTP\u5934\n\t\theader ('Content-Type: ' . $mimeType);\n\t\theader ('Accept-Ranges: none'); \n\t\theader ('Last-Modified: ' . $gmdate_modified);\n\t\theader ('Content-Length: ' . $dataSize);\n\t\t\/\/\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u7981\u6b62\u6d4f\u89c8\u5668\u7f13\u5b58\uff0c\u5219\u8bbe\u7f6e\u76f8\u5e94\u7684HTTP\u5934\u4fe1\u606f\n\t\tif(BROWSER_CACHE_DISABLE){\n\t\t\t$this->debug(3, \"Browser cache is disabled so setting non-caching headers.\");\n\t\t\theader('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');\n\t\t\theader(\"Pragma: no-cache\");\n\t\t\theader('Expires: ' . gmdate ('D, d M Y H:i:s', time()));\n\t\t\/\/\u5426\u5219\u6309\u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\u7f13\u5b58\u65f6\u95f4\n\t\t} else {\n\t\t\t$this->debug(3, \"Browser caching is enabled\");\n\t\t\theader('Cache-Control: max-age=' . BROWSER_CACHE_MAX_AGE . ', must-revalidate');\n\t\t\theader('Expires: ' . $gmdate_expires);\n\t\t}\n\t\t\/\/\u8fd0\u884c\u6210\u529f\u8fd4\u56de\u771f\n\t\treturn true;\n\t}\n\t\/*\u81ea\u5b9a\u4e49\u7684\u9a8c\u8bc1\u51fd\u6570*\/\n\tprotected function securityChecks(){\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u83b7\u53d6$_GET\u6570\u7ec4\u4e2d\u7684\u53c2\u6570\uff0c\u5e76\u5141\u8bb8\u8bbe\u7f6e\u9ed8\u8ba4\u503c*\/\n\tprotected function param($property, $default = ''){\n\t  \t\/\/\u5982\u679c\u53c2\u6570\u5b58\u5728\u5219\u8fd4\u56de\u6b64\u53c2\u6570\n\t\tif (isset ($_GET[$property])) {\n\t\t  \treturn $_GET[$property];\n\t\t\/\/\u4e0d\u5b58\u5728\u7684\u8bdd\u8fd4\u56de\u9ed8\u8ba4\u503c\n\t\t} else {\n\t\t\treturn $default;\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u6839\u636e\u4f20\u5165mime\u7c7b\u578b\uff0c\u6253\u5f00\u56fe\u50cf\u8d44\u6e90*\/\n\tprotected function openImage($mimeType, $src){\n\t\tswitch ($mimeType) {\n\t\t\tcase 'image\/jpeg':\n\t\t\t\t$image = imagecreatefromjpeg ($src);\n\t\t\t\tbreak;\n\n\t\t\tcase 'image\/png':\n\t\t\t\t$image = imagecreatefrompng ($src);\n\t\t\t\tbreak;\n\n\t\t\tcase 'image\/gif':\n\t\t\t\t$image = imagecreatefromgif ($src);\n\t\t\t\tbreak;\n\t\t\t\/\/\u4e0d\u662f\u8fd9\u4e09\u79cd\u7684\u8bdd\uff0c\u811a\u672c\u9000\u51fa\n\t\t\tdefault:\n\t\t\t\t$this->error(\"Unrecognised mimeType\");\n\t\t}\n\t\t\/\/\u8fd4\u56de\u56fe\u50cf\u8d44\u6e90\n\t\treturn $image;\n\t}\n\t\/*\u6ca1\u5565\u8bf4\u7684\uff0c\u83b7\u53d6\u5ba2\u6237\u7aefIP*\/\n\tprotected function getIP(){\n\t\t$rem = @$_SERVER[\"REMOTE_ADDR\"];\n\t\t$ff = @$_SERVER[\"HTTP_X_FORWARDED_FOR\"];\n\t\t$ci = @$_SERVER[\"HTTP_CLIENT_IP\"];\n\t\tif(preg_match('\/^(?:192.168|172.16|10.|127.)\/', $rem)){ \n\t\t\tif($ff){ return $ff; }\n\t\t\tif($ci){ return $ci; }\n\t\t\treturn $rem;\n\t\t} else {\n\t\t\tif($rem){ return $rem; }\n\t\t\tif($ff){ return $ff; }\n\t\t\tif($ci){ return $ci; }\n\t\t\treturn \"UNKNOWN\";\n\t\t}\n\t}\n\t\/*debug\u8fd0\u884c\u65e5\u5fd7\u51fd\u6570\uff0c\u7528\u6765\u5411\u7cfb\u7edf\u65e5\u5fd7\u8bb0\u5f55\u64cd\u4f5c\u4fe1\u606f*\/\n\tprotected function debug($level, $msg){\n\t  \t\/\/\u5982\u679c\u5f00\u542f\u4e86debug\uff0c\u5e76\u4e14$level\u4e5f\u5c31\u662f\u8c03\u8bd5\u7ea7\u522b\u5c0f\u4e8e\u7b49\u4e8e\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u503c\uff0c\u5219\u5f00\u59cb\u8bb0\u5f55\n\t  \tif(DEBUG_ON && $level <= DEBUG_LEVEL){\n\t\t\t\/\/\u683c\u5f0f\u5316\u5e76\u8bb0\u5f55\u5f00\u59cb\u65f6\u95f4\uff0c\u4fdd\u7559\u5c0f\u6570\u70b9\u540e6\u4f4d,\u8fd9\u4e2a\u65f6\u95f4\u4ee3\u8868\u5b9e\u4f8b\u5316\u7c7b\u540e\u5230\u8fd9\u4e2adebug\u6267\u884c\u6240\u7ecf\u5386\u7684\u65f6\u95f4\n\t\t  \t$execTime = sprintf('%.6f', microtime(true) - $this->startTime);\n\t\t\t\/\/\u8fd9\u4e2a\u503c\u4ee3\u8868\u4ece\u4e0a\u6b21debug\u7ed3\u675f\uff0c\u5230\u8fd9\u6b21debug\u7684\u7528\u65f6\n\t\t\t$tick = sprintf('%.6f', 0);\n\t\t\t\/\/\u5982\u679c\u4e0a\u6b21debug\u65f6\u95f4\u5b58\u5728\uff0c\u5219\u7528\u5f53\u524d\u65f6\u95f4\u51cf\u53bb\u4e0a\u6b21debug\u65f6\u95f4\uff0c\u5f97\u51fa\u5dee\u503c\n\t\t\tif($this->lastBenchTime > 0){\n\t\t\t\t$tick = sprintf('%.6f', microtime(true) - $this->lastBenchTime);\n\t\t\t}\n\t\t\t\/\/\u5c06\u65f6\u95f4\u66f4\u65b0\n\t\t\t$this->lastBenchTime = microtime(true);\n\t\t\t\/\/\u5c06debug\u4fe1\u606f\u5199\u5230\u7cfb\u7edf\u65e5\u5fd7\u4e2d\n\t\t\terror_log(\"TimThumb Debug line \" . __LINE__ . \" [$execTime : $tick]: $msg\");\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8bb0\u5f55\u672a\u77e5BUG*\/\n\tprotected function sanityFail($msg){\n\t  \t\/\/\u8bb0\u5f55BUG\u4fe1\u606f\n\t\treturn $this->error(\"There is a problem in the timthumb code. Message: Please report this error at <a href='http:\/\/code.google.com\/p\/timthumb\/issues\/list'>timthumb's bug tracking page<\/a>: $msg\");\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u8fd4\u56de<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6587\u4ef6\u7684MIME\u4fe1\u606f*\/\n\tprotected function getMimeType($file){\n\t  \t\/\/\u83b7\u53d6<strong><strong>\u56fe\u7247<\/strong><\/strong>\u6587\u4ef6\u7684\u4fe1\u606f\n\t  \t$info = getimagesize($file);\n\t\t\/\/\u6210\u529f\u5219\u8fd4\u56deMIME\u4fe1\u606f\n\t\tif(is_array($info) && $info['mime']){\n\t\t\treturn $info['mime'];\n\t\t}\n\t\t\/\/\u5931\u8d25\u8fd4\u56de\u7a7a\n\t\treturn '';\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u68c0\u6d4b\u5e76\u8bbe\u7f6ephp\u8fd0\u884c\u65f6\u6700\u5927\u5360\u7528\u5185\u5b58\u7684\u503c*\/\n\tprotected function setMemoryLimit(){\n\t  \t\/\/\u83b7\u53d6php.ini\u4e2d\u7684\u6700\u5927\u5185\u5b58\u5360\u7528\u7684\u503c\n\t  \t$inimem = ini_get('memory_limit');\n\t\t\/\/\u5c06\u4e0a\u9762\u5f97\u5230\u7684\u503c\u8f6c\u6362\u4e3a\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\u6570\u503c\n\t\t$inibytes = timthumb::returnBytes($inimem);\n\t\t\/\/\u7b97\u51fa\u914d\u7f6e\u6587\u4ef6\u4e2d\u5185\u5b58\u9650\u5236\u7684\u503c\n\t\t$ourbytes = timthumb::returnBytes(MEMORY_LIMIT);\n\t\t\/\/\u5982\u679cphp\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u503c\u5c0f\u4e8e\u81ea\u5df1\u8bbe\u5b9a\u7684\u503c\n\t\tif($inibytes < $ourbytes){\n\t\t  \t\/\/\u5219\u5c06php.ini\u914d\u7f6e\u4e2d\u5173\u4e8e\u6700\u5927\u5185\u5b58\u7684\u503c\u8bbe\u7f6e\u4e3a\u81ea\u5df1\u8bbe\u5b9a\u7684\u503c\n\t\t  \tini_set ('memory_limit', MEMORY_LIMIT);\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u6539\u53d8\u5185\u5b58\u64cd\u4f5c\uff0c\u7ea7\u522b3\n\t\t\t$this->debug(3, \"Increased memory from $inimem to \" . MEMORY_LIMIT);\n\t\t\/\/\u5982\u679c\u81ea\u5df1\u8bbe\u7f6e\u7684\u503c\u5c0f\u4e8ephp.ini\u4e2d\u7684\u503c\n\t\t} else {\n\t\t  \t\/\/\u5219\u4e0d\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\uff0c\u5199\u65e5\u5fd7\u8bb0\u5f55\u6b64\u6761\u4fe1\u606f\u5373\u53ef\uff0c\u7ea7\u522b3\n\t\t\t$this->debug(3, \"Not adjusting memory size because the current setting is \" . $inimem . \" and our size of \" . MEMORY_LIMIT . \" is smaller.\");\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u5c06G, KB, MB \u8f6c\u4e3aB(\u5b57\u8282)*\/\n\tprotected static function returnBytes($size_str){\n\t  \t\/\/\u53d6\u6700\u540e\u4e00\u4e2a\u5355\u4f4d\u503c\uff0c\u8fdb\u884c\u8f6c\u6362\u64cd\u4f5c\uff0c\u5e76\u8fd4\u56de\u8f6c\u6362\u540e\u7684\u503c\n\t\tswitch (substr ($size_str, -1))\n\t\t{\n\t\t\tcase 'M': case 'm': return (int)$size_str * 1048576;\n\t\t\tcase 'K': case 'k': return (int)$size_str * 1024;\n\t\t\tcase 'G': case 'g': return (int)$size_str * 1073741824;\n\t\t\tdefault: return $size_str;\n\t\t}\n\t}\n\t\/*\u6b64\u51fd\u6570\u7528\u6765\u5c06url\u4e2d\u7684\u8d44\u6e90\u8bfb\u53d6\u5230tempfile\u6587\u4ef6\u4e2d*\/\n\tprotected function getURL($url, $tempfile){\n\t  \t\/\/\u91cd\u7f6e\u4e0a\u6b21url\u8bf7\u6c42\u9519\u8bef\u4fe1\u606f\n\t  \t$this->lastURLError = false;\n\t  \t\/\/\u8fdb\u884curl\u7f16\u7801\n\t\t$url = preg_replace('\/ \/', '%20', $url);\n\t\t\/\/\u4f18\u5148\u4f7f\u7528curl\u6269\u5c55\n\t\tif(function_exists('curl_init')){\n\t\t  \t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u5c06\u4f7f\u7528curl\u6269\u5c55\u8bbf\u95eeurl\uff0c\u7ea7\u522b3\n\t\t  \t$this->debug(3, \"Curl is installed so using it to fetch URL.\");\n\t\t\t\/\/\u6253\u5f00\u6587\u4ef6\n\t\t\tself::$curlFH = fopen($tempfile, 'w');\n\t\t\t\/\/\u5982\u679c\u6253\u5f00\u5931\u8d25\uff0c\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u5e76\u9000\u51fa\n\t\t\tif(! self::$curlFH){\n\t\t\t\t$this->error(\"Could not open $tempfile for writing.\");\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u91cd\u7f6e\u5199\u5165\u957f\u5ea6\n\t\t\tself::$curlDataWritten = 0;\n\t\t\t\/\/\u5199\u65e5\u5fd7\uff0c\u8bb0\u5f55\u8bbf\u95ee\u7684url\u4fe1\u606f\uff0c\u7ea7\u522b3\n\t\t\t$this->debug(3, \"Fetching url with curl: $url\");\n\t\t\t\/\/\u521d\u59cb\u5316curl\n\t\t\t$curl = curl_init($url);\n\t\t\t\/\/curl\u9009\u9879\u8bbe\u7f6e\n\t\t\tcurl_setopt ($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);\n\t\t\tcurl_setopt ($curl, CURLOPT_USERAGENT, \"Mozilla\/5.0 (Windows NT 6.1) AppleWebKit\/534.30 (KHTML, like Gecko) Chrome\/12.0.742.122 Safari\/534.30\");\n\t\t\tcurl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);\n\t\t\tcurl_setopt ($curl, CURLOPT_HEADER, 0);\n\t\t\tcurl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);\n\t\t\t\/\/\u5173\u95ed\u4f1a\u8bdd\u65f6\u6267\u884ccurlWrite\n\t\t\tcurl_setopt ($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite');\n\t\t\t@curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);\n\t\t\t@curl_setopt ($curl, CURLOPT_MAXREDIRS, 10);\n\t\t\t\/\/\u6267\u884c\u672c\u6b21\u8bf7\u6c42\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u7ed9$curlResult\n\t\t\t$curlResult = curl_exec($curl);\n\t\t\t\/\/\u91ca\u653e\u6587\u4ef6\u8d44\u6e90\n\t\t\tfclose(self::$curlFH);\n\t\t\t\/\/\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u53d7\u5230\u7684HTTP\u7801\n\t\t\t$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n\t\t\t\/\/\u5982\u679c\u662f404\uff0c\u90a3\u4e48\u8bbe\u7f6e404\u9519\u8bef\u5e76\u9000\u51fa\n\t\t\tif($httpStatus == 404){\n\t\t\t\t$this->set404();\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u8bf7\u6c42\u6210\u529f\n\t\t\tif($curlResult){\n\t\t\t  \t\/\/\u5173\u95edcurl\uff0c\u5e76\u6267\u884ccurlWrite\u5c06\u6570\u636e\u5199\u5230\u6587\u4ef6\u4e2d\n\t\t\t  \tcurl_close($curl);\n\t\t\t  \t\/\/\u8fd4\u56de\u771f\uff0c\u8bf7\u6c42\u5b8c\u6210\n\t\t\t\treturn true;\n\t\t\t\/\/\u5982\u679c\u8bf7\u6c42\u4e0d\u6210\u529f\n\t\t\t} else {\n\t\t\t  \t\/\/\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n\t\t\t  \t$this->lastURLError = curl_error($curl);\n\t\t\t\t\/\/\u5173\u95ed\u8d44\u6e90\n\t\t\t\tcurl_close($curl);\n\t\t\t\t\/\/\u6267\u884c\u4e0d\u6210\u529f\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\/\/\u5982\u679c\u4e0d\u652f\u6301curl\uff0c\u7528file_get_contents\u83b7\u53d6\u6570\u636e\n\t\t} else {\n\t\t  \t\/\/\u83b7\u53d6\u6570\u636e\n\t\t  \t$img = @file_get_contents ($url);\n\t\t\t\/\/\u5982\u679c\u83b7\u53d6\u5931\u8d25\n\t\t\tif($img === false){\n\t\t\t  \t\/\/\u8bb0\u5f55\u8fd4\u56de\u7684\u9519\u8bef\u4fe1\u606f\u6570\u7ec4\n\t\t\t  \t$err = error_get_last();\n\t\t\t  \t\/\/\u5982\u679c\u8bb0\u5f55\u5230\u4e86\uff0c\u5e76\u4e14\u6709\u9519\u8bef\u4fe1\u606f\n\t\t\t\tif(is_array($err) && $err['message']){\n\t\t\t\t  \t\/\/\u5219\u8bb0\u5f55\u8fd9\u4e2a\u9519\u8bef\u4fe1\u606f\n\t\t\t\t  \t$this->lastURLError = $err['message'];\n\t\t\t\t\/\/\u5426\u5219\u7684\u8bdd\u8bb0\u5f55\u6574\u4e2a\u9519\u8bef\u4fe1\u606f\n\t\t\t\t} else {\n\t\t\t\t\t$this->lastURLError = $err;\n\t\t\t\t}\n\t\t\t\t\/\/\u5982\u679c\u9519\u8bef\u4fe1\u606f\u4e2d\u6709404\uff0c\u5219\u8bbe\u7f6e\u4e3a404\u9519\u8bef\n\t\t\t\tif(preg_match('\/404\/', $this->lastURLError)){\n\t\t\t\t\t$this->set404();\n\t\t\t\t}\n\t\t\t\t\/\/\u8fd4\u56de\u5047\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u5982\u679c\u5c06\u8bfb\u53d6\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\u5199\u5165\u6587\u4ef6\u5931\u8d25\n\t\t\tif(! file_put_contents($tempfile, $img)){\n\t\t\t  \t\/\/\u5199\u9519\u8bef\u4fe1\u606f\u5e76\u9000\u51fa\u6267\u884c\n\t\t\t\t$this->error(\"Could not write to $tempfile.\");\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\/\/\u6ca1\u95ee\u9898\u7684\u8bdd\u6267\u884c\u6210\u529f\n\t\t\treturn true;\n\t\t}\n\n\t}\n\t\/*\u6b64\u51fd\u6570\u8f93\u51fa\u6307\u5b9a\u7684<strong><strong>\u56fe\u7247<\/strong><\/strong>\uff0c\u7528\u4e8e\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u4e2d*\/\n\tprotected function serveImg($file){\n\t  \t\/\/\u83b7\u53d6\u56fe\u50cf\u4fe1\u606f\n\t  \t$s = getimagesize($file);\n\t\t\/\/\u5982\u679c\u83b7\u53d6\u4e0d\u5230\u56fe\u50cf\u4fe1\u606f\uff0c\u63a8\u51fa\n\t\tif(! ($s && $s['mime'])){\n\t\t\treturn false;\n\t\t}\n\t\t\/\/\u8bbe\u7f6ehttp\u5934\uff0c\u8f93\u51fa<strong><strong>\u56fe\u7247<\/strong><\/strong>\n\t\theader ('Content-Type: ' . $s['mime']);\n\t\theader ('Content-Length: ' . filesize($file) );\n\t\theader ('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');\n\t\theader (\"Pragma: no-cache\");\n\t\t\/\/\u4f7f\u7528readfile\u8f93\u51fa<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t$bytes = @readfile($file);\n\t\tif($bytes > 0){\n\t\t\treturn true;\n\t\t}\n\t\t\/\/\u5982\u679c\u5931\u8d25\uff0c\u4f7f\u7528file_get_contents\u548cecho\u8f93\u51fa<strong><strong>\u56fe\u7247<\/strong><\/strong>\n<\/em><\/em>\t\t$content = @file_get_contents ($file);\n\t\tif ($content != FALSE){\n\t\t\techo $content;\n\t\t\treturn true;\n\t\t}\n\t\t\/\/\u8fd8\u5931\u8d25\u7684\u8bdd\u8fd4\u56de\u5047\n<\/em><\/em>\t\treturn false;\n\t}\n\t\/*\u6b64\u51fd\u6570\u8bbe\u7f6e404 \u9519\u8bef\u7801*\/<\/em>\n\tprotected function set404(){\n\t\t$this->is404 = true;\n\t}\n\t\/*\u6b64\u51fd\u6570\u8fd4\u56de404\u9519\u8bef\u7801*\/<\/em>\n\tprotected function is404(){\n\t\treturn $this->is404;\n\t}\n}<\/code><\/pre>\n\n\n\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

TimThumb \u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u6d01\u65b9\u4fbf\u7528\u4e8e\u88c1\u56fe\u7684 PHP \u7a0b\u5e8f\uff0c\u53ea\u8981\u7ed9\u4ed6\u8bbe\u7f6e\u4e00\u4e9b\u53c2\u6570\uff0c\u5b83\u5c31\u53ef\u4ee5\u751f\u6210\u7f29\u7565 […]<\/p>\n","protected":false},"author":1,"featured_media":43088,"comment_status":"open","ping_status":"","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[17,13,65],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/47419"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=47419"}],"version-history":[{"count":0,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/47419\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/43088"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=47419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=47419"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=47419"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}