{"id":63,"date":"2015-12-30T14:31:53","date_gmt":"2015-12-30T06:31:53","guid":{"rendered":"http:\/\/www.tra56.com\/?p=63"},"modified":"2015-12-30T14:31:53","modified_gmt":"2015-12-30T06:31:53","slug":"using-php-generated-qr-code-qr-codes","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/63.html","title":{"rendered":"\u4f7f\u7528PHP QR Code\u751f\u6210\u4e8c\u7ef4\u7801"},"content":{"rendered":"
\n\tHP QR Code\u662f\u4e00\u4e2aPHP\u4e8c\u7ef4\u7801\u751f\u6210\u7c7b\u5e93\uff0c\u5229\u7528\u5b83\u53ef\u4ee5\u8f7b\u677e\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5b98\u7f51\u63d0\u4f9b\u4e86\u4e0b\u8f7d\u548c\u591a\u4e2a\u6f14\u793ademo\uff0c\u67e5\u770b\u5730\u5740\uff1a<\/span>\n<\/p>\n \n\t<\/p>\n \n\t\t\u4e0b\u8f7d\u5b98\u7f51\u63d0\u4f9b\u7684\u7c7b\u5e93\u540e\uff0c\u53ea\u9700\u8981\u4f7f\u7528phpqrcode.php\u5c31\u53ef\u4ee5\u751f\u6210\u4e8c\u7ef4\u7801\u4e86\uff0c\u5f53\u7136\u60a8\u7684PHP\u73af\u5883\u5fc5\u987b\u5f00\u542f\u652f\u6301GD2\u3002\n\t<\/p>\n \n\t\t\n\t<\/p>\n \n\t\tphpqrcode.php\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5173\u952e\u7684png()\u65b9\u6cd5\uff0c\u5176\u4e2d\n\t<\/p>\n \n\t\t\u53c2\u6570$text\u8868\u793a\u751f\u6210\u4e8c\u4f4d\u7684\u7684\u4fe1\u606f\u6587\u672c\uff1b\n\t<\/p>\n \n\t\t\u53c2\u6570$outfile\u8868\u793a\u662f\u5426\u8f93\u51fa\u4e8c\u7ef4\u7801\u56fe\u7247 \u6587\u4ef6\uff0c\u9ed8\u8ba4\u5426\uff1b\n\t<\/p>\n \n\t\t\u53c2\u6570$level\u8868\u793a\u5bb9\u9519\u7387\uff0c\u4e5f\u5c31\u662f\u6709\u88ab\u8986\u76d6\u7684\u533a\u57df\u8fd8\u80fd\u8bc6\u522b\uff0c\u5206\u522b\u662f L\uff08QR_ECLEVEL_L\uff0c7%\uff09\uff0cM\uff08QR_ECLEVEL_M\uff0c15%\uff09\uff0cQ\uff08QR_ECLEVEL_Q\uff0c25%\uff09\uff0cH\uff08QR_ECLEVEL_H\uff0c30%\uff09\uff1b\n\t<\/p>\n \n\t\t\u53c2\u6570$size\u8868\u793a\u751f\u6210\u56fe\u7247\u5927\u5c0f\uff0c\u9ed8\u8ba4\u662f3\uff1b\u53c2\u6570$margin\u8868\u793a\u4e8c\u7ef4\u7801\u5468\u56f4\u8fb9\u6846\u7a7a\u767d\u533a\u57df\u95f4\u8ddd\u503c\uff1b\n\t<\/p>\n \n\t\t\u53c2\u6570$saveandprint\u8868\u793a\u662f\u5426\u4fdd\u5b58\u4e8c\u7ef4\u7801\u5e76\u663e\u793a\u3002\n\t<\/p>\n \n\t\t\n\t<\/p>\n \n\t\t. \u4ee3\u7801\u5982\u4e0b:\n\t<\/p>\n \u8c03\u7528PHP QR Code\u975e\u5e38\u7b80\u5355\uff0c\u5982\u4e0b\u4ee3\u7801\u5373\u53ef\u751f\u6210\u4e00\u5f20\u5185\u5bb9\u4e3a\"https:\/\/www.tra56.com\/\"\u7684\u4e8c\u7ef4\u7801.<\/span><\/span>\n<\/p>\n \n\t<\/p>\n \u90a3\u4e48\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u4f1a\u5728\u4e8c\u7ef4\u7801\u7684\u4e2d\u95f4\u52a0\u4e0a\u81ea\u5df1\u7684LOGO\uff0c\u5df2\u589e\u5f3a\u5ba3\u4f20\u6548\u679c\u3002\u90a3\u5982\u4f55\u751f\u6210\u542b\u6709logo\u7684\u4e8c\u7ef4\u7801\u5462\uff1f\u5176\u5b9e\u539f\u7406\u5f88\u7b80\u5355\uff0c\u5148\u4f7f\u7528PHP QR Code\u751f\u6210\u4e00\u5f20\u4e8c\u7ef4\u7801\u56fe\u7247\uff0c\u7136\u540e\u518d\u5229\u7528php\u7684image\u76f8\u5173\u51fd\u6570\uff0c\u5c06\u4e8b\u5148\u51c6\u5907\u597d\u7684logo\u56fe\u7247\u52a0\u5165\u5230\u521a\u751f\u6210\u7684\u539f\u59cb\u4e8c\u7ef4\u7801\u56fe\u7247\u4e2d\u95f4\uff0c\u7136\u540e\u91cd\u65b0\u751f\u6210\u4e00\u5f20\u65b0 \u7684\u4e8c\u7ef4\u7801\u56fe\u7247\u3002<\/span> \n\t<\/p>\n \n<\/span>\n<\/p>\n \n\t<\/p>\n \n\t\t\u7531\u4e8e\u4e8c\u7ef4\u7801\u5141\u8bb8\u6709\u4e00\u5b9a\u7684\u5bb9\u9519\u6027\uff0c\u4e00\u822c\u7684\u4e8c\u7ef4\u7801\u5373\u4f7f\u5728\u906e\u4f4f\u90e8\u5206\u4f46\u4ecd\u7136\u80fd\u591f\u89e3\u7801\uff0c\u7ecf\u5e38\u6211\u4eec\u626b\u63cf\u4e8c\u7ef4\u7801\u7684\u65f6\u5019\u626b\u63cf\u5230\u751a\u81f3\u4e0d\u5230\u4e00\u534a\u65f6\u5c31\u80fd\u89e3\u7801\u626b\u63cf\u7ed3\u679c\uff0c\u8fd9\u662f\u56e0\u4e3a\u751f\u6210\u5668\u4f1a\u5c06\u90e8\u5206\u4fe1\u606f\u91cd\u590d\u8868\u793a\u6765\u63d0\u9ad8\u5176\u5bb9\u9519\u5ea6\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728\u4e8c\u7ef4\u7801\u4e2d\u95f4\u52a0\u4e2aLOGO\u56fe\u7247\u5e76\u4e0d\u5f71\u54cd\u89e3\u7801\u7ed3\u679c\u7684\u539f\u56e0\u3002\n\t<\/p>\n \n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":" HP QR Code\u662f\u4e00\u4e2aPHP\u4e8c\u7ef4\u7801\u751f\u6210\u7c7b\u5e93\uff0c\u5229\u7528\u5b83\u53ef\u4ee5\u8f7b\u677e\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u5b98\u7f51\u63d0\u4f9b\u4e86\u4e0b\u8f7d\u548c\u591a\u4e2a\u6f14\u793ademo\uff0c\u67e5 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":64,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/63\/revisions\/64"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}http:\/\/phpqrcode.sourceforge.net\/<\/pre>\n
public static function png($text, $outfile=false, $level=QR_ECLEVEL_L, $size=3, $margin=4, $saveandprint=false) \r\n{ \r\n $enc = QRencode::factory($level, $size, $margin); \r\n return $enc->encodePNG($text, $outfile, $saveandprint=false); \r\n} <\/pre>\n
include 'phpqrcode.php'; \r\nQRcode::png('https:\/\/www.tra56.com\/');<\/pre>\n
\n. \u4ee3\u7801\u5982\u4e0b:<\/span><\/span>\n<\/p>\ninclude 'phpqrcode.php'; \r\n$value = 'https:\/\/www.tra56.com\/'; \/\/\u4e8c\u7ef4\u7801\u5185\u5bb9 \r\n$errorCorrectionLevel = 'L';\/\/\u5bb9\u9519\u7ea7\u522b \r\n$matrixPointSize = 6;\/\/\u751f\u6210\u56fe\u7247\u5927\u5c0f \r\n\/\/\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u7247 \r\nQRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2); \r\n$logo = 'logo.png';\/\/\u51c6\u5907\u597d\u7684logo\u56fe\u7247 \r\n$QR = 'qrcode.png';\/\/\u5df2\u7ecf\u751f\u6210\u7684\u539f\u59cb\u4e8c\u7ef4\u7801\u56fe \r\n\r\nif ($logo !== FALSE) { \r\n $QR = imagecreatefromstring(file_get_contents($QR)); \r\n $logo = imagecreatefromstring(file_get_contents($logo)); \r\n $QR_width = imagesx($QR);\/\/\u4e8c\u7ef4\u7801\u56fe\u7247\u5bbd\u5ea6 \r\n $QR_height = imagesy($QR);\/\/\u4e8c\u7ef4\u7801\u56fe\u7247\u9ad8\u5ea6 \r\n $logo_width = imagesx($logo);\/\/logo\u56fe\u7247\u5bbd\u5ea6 \r\n $logo_height = imagesy($logo);\/\/logo\u56fe\u7247\u9ad8\u5ea6 \r\n $logo_qr_width = $QR_width \/ 5; \r\n $scale = $logo_width\/$logo_qr_width; \r\n $logo_qr_height = $logo_height\/$scale; \r\n $from_width = ($QR_width - $logo_qr_width) \/ 2; \r\n \/\/\u91cd\u65b0\u7ec4\u5408\u56fe\u7247\u5e76\u8c03\u6574\u5927\u5c0f \r\n imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, \r\n $logo_qr_height, $logo_width, $logo_height); \r\n} \r\n\/\/\u8f93\u51fa\u56fe\u7247 \r\nimagepng($QR, 'helloweixin.png'); \r\necho '<img src=\"helloweixin.png\">';<\/pre>\n
include 'phpqrcode.php'; \r\n$value = 'https:\/\/www.tra56.com\/'; \/\/\u4e8c\u7ef4\u7801\u5185\u5bb9 \r\n$errorCorrectionLevel = 'L';\/\/\u5bb9\u9519\u7ea7\u522b \r\n$matrixPointSize = 6;\/\/\u751f\u6210\u56fe\u7247\u5927\u5c0f \r\n\/\/\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u7247 \r\nQRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2); \r\n$logo = 'logo.png';\/\/\u51c6\u5907\u597d\u7684logo\u56fe\u7247 \r\n$QR = 'qrcode.png';\/\/\u5df2\u7ecf\u751f\u6210\u7684\u539f\u59cb\u4e8c\u7ef4\u7801\u56fe \r\n\r\nif ($logo !== FALSE) { \r\n $QR = imagecreatefromstring(file_get_contents($QR)); \r\n $logo = imagecreatefromstring(file_get_contents($logo)); \r\n $QR_width = imagesx($QR);\/\/\u4e8c\u7ef4\u7801\u56fe\u7247\u5bbd\u5ea6 \r\n $QR_height = imagesy($QR);\/\/\u4e8c\u7ef4\u7801\u56fe\u7247\u9ad8\u5ea6 \r\n $logo_width = imagesx($logo);\/\/logo\u56fe\u7247\u5bbd\u5ea6 \r\n $logo_height = imagesy($logo);\/\/logo\u56fe\u7247\u9ad8\u5ea6 \r\n $logo_qr_width = $QR_width \/ 5; \r\n $scale = $logo_width\/$logo_qr_width; \r\n $logo_qr_height = $logo_height\/$scale; \r\n $from_width = ($QR_width - $logo_qr_width) \/ 2; \r\n \/\/\u91cd\u65b0\u7ec4\u5408\u56fe\u7247\u5e76\u8c03\u6574\u5927\u5c0f \r\n imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, \r\n $logo_qr_height, $logo_width, $logo_height); \r\n} \r\n\/\/\u8f93\u51fa\u56fe\u7247 \r\nimagepng($QR, 'helloweixin.png'); \r\necho '<img src=\"helloweixin.png\">';<\/pre>\n