Google APIを活用してQRコードの生成
Google APIを活用します。
Google Developersのグラフ作成用API「Google Chart Tools」の中にあるInfographicsにQRコード作成機能があります。
入力フォーム qrcode.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>QRコード入力画面</title> <style> body{ text-align:center; } </style> </head> <body> <p>QRコードにしたい文字を入力して下さい。</p> <form action="qrcode.php" method="get"> キーワード:<input type="text" name="keyword" size="40"> <input type="submit" value="検索"> </form> </body> </html>
実行ファイル qrcode.php
QRコードを生成するためのプログラムとできあがったQRコード画像をダウンロードしてもらうプログラムを打ちます。
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>QRコード作成サイト</title> <style> body{ text-align:center; } </style> </head> <body> <p>生成されたQRコード</p> <?php $keyword=$_GET["keyword"]; $keywordurl=urlencode($keyword); $url="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=$keywordurl"; ?> <img src="<?php echo $url; ?>"> <!-- ダウンロード用ボタン--> <form method="get" action="download.php"> <input type="hidden" name="url" value="<?php echo $url?>"> <input type="submit" value="QRコード画像をダウンロード"> </form> </body> </html>
ダウンロード実行ファイル download.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>QRコード作成サイト</title> </head> <body> <?php $file=$_GET["url"]; $fullpath=$file; $filename='qrcode.png'; header("Content-type:image/png"); header('Content-Disposition: attachment; filename="' .$filename .'"'); readfile($fullpath); ?> </body> </html>
出来上がった本サイトのQRコード