Dynamically generating a QR code with PHP [closed]

2019-01-12 15:47发布

I'm trying to generate QR codes on my website. All they have to do is have a URL in them, which a variable on my site will provide. What would be the easiest way to do this?

标签: php qr-code
7条回答
疯言疯语
2楼-- · 2019-01-12 16:10

I have been using google qrcode api for sometime, but I didn't quite like this because it requires me to be on the Internet to access the generated image.

I did a little comand-line research and found out that linux has a command line tool qrencode for generating qr-codes.

I wrote this little script. And the good part is that the generated image is less than 1KB in size. Well the supplied data is simply a url.

$url = ($_SERVER['HTTPS'] ? "https://" : "http://").$_SERVER['HTTP_HOST'].'/profile.php?id='.$_GET['pid'];
$img = shell_exec('qrencode --output=- -m=1 '.escapeshellarg($url));

$imgData = "data:image/png;base64,".base64_encode($img);

Then in the html I load the image:

<img class="emrQRCode" src="<?=$imgData ?>" />

You just need to have installed it. [most imaging apps on linux would have installed it under the hood without you realizing.

查看更多
登录 后发表回答