{"id":790,"date":"2021-03-23T14:23:04","date_gmt":"2021-03-23T14:23:04","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=790"},"modified":"2021-03-23T10:14:49","modified_gmt":"2021-03-23T10:14:49","slug":"php-qr-code-generate","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/php\/php-qr-code-generate\/","title":{"rendered":"PHP QR Code Generate"},"content":{"rendered":"<p>In one of my projects I suddenly needed to generate QR code. I tried searching for some free QR Code generator Library, but didn&#8217;t find anything suitable and reliable except the PEAR package which I had used many years back. I was not willing to use the package as the last Alpha release was about 9 years ago. But as there were no suitable package so ultimately used that. The PHP version is 7.2.34.<\/p>\n<p>Using the library is simple and pretty straightforward<\/p>\n<p>Installation:<\/p>\n<pre class='wp-code-highlight prettyprint'>$pear install channel:\/\/pear.php.net\/Image_QRCode-0.1.3<\/pre>\n<p>PHP Code<\/p>\n<pre class='wp-code-highlight prettyprint'>require_once '.\/Image_QRCode-0.1.3\/Image\/QRCode.php';\r\n\r\n$qrcode = new Image_QRCode();\r\n\r\n$options = array( \"image_type\" =&gt; \"png\", \"output_type\" =&gt; \"return\" );\r\n\r\n$gd_object = $qrcode-&gt;makeCode(\"STRING\", $options);\r\n\r\n$sx = imagesx($gd_object);\r\n\r\n$sy = imagesy($gd_object);\r\n\r\n\/\/The returned object is an \"image resource\". Which can be saved as an image or can be used as a watermark. Below example is of watermarking which will placed at the bottom right on the main image\r\n\/\/imagesx($im) - $sx === the x position where the qr code will be placed\r\n\/\/imagesy($im) - $sy === the y position where the qr code will be placed\r\n\/\/0, 0 == the start point from where the QRCode image will start to be be copied - 0,0 means from the top left or start of the image - if some other value is given then it will be cropped\r\n\/\/imagesx($gd_object), imagesy($gd_object), == the end point of the qr code image. The current copies upto the bottom right or end point of the image. Any value lesser will cause a cropped image. \/\/75 == is the quality of the overall image.\r\n\r\n$im = imagecreatefromstring($data);\u00a0 \/\/ imagecreatefrompng($filename)\r\n\r\nimagecopymerge($im, $gd_object, imagesx($im) - $sx, imagesy($im) - $sy, 0, 0, imagesx($gd_object), imagesy($gd_object), 75);\r\n\r\nob_start(); \/\/Turn on output buffering\r\n\r\nimagepng($im); \/\/Generate your image\r\n\r\n$outputImage = ob_get_contents(); \/\/ get the image as a string in a variable\r\n\r\nob_end_clean(); \/\/Turn off output buffering and clean\r\n\r\nfile_put_contents(\"IMAGE.PNG\",$outputImage);\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In one of my projects I suddenly needed to generate QR code. I tried searching for some free QR Code generator Library, but didn&#8217;t find anything suitable and reliable except the PEAR package which I had used many years back. I was not willing to use the package as the last Alpha release was about&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/php\/php-qr-code-generate\/\">Continue reading <span class=\"screen-reader-text\">PHP QR Code Generate<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[265,268,266,267,270,272,271,273,269],"class_list":["post-790","post","type-post","status-publish","format-standard","hentry","category-php","tag-gd-library","tag-php-gd-library","tag-php-image","tag-php-image-manipulation","tag-php-qr-code","tag-php-qr-code-generation","tag-php-qrcode","tag-php-qrcode-generation","tag-php-watermark","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=790"}],"version-history":[{"count":7,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/790\/revisions"}],"predecessor-version":[{"id":792,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/790\/revisions\/792"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}