LoginSignup
1
0

More than 3 years have passed since last update.

QRコードを生成するパッケージを使ってみた

Last updated at Posted at 2020-09-23

QRコードを生成するパッケージを使ってみた

QRコードをパッケージを利用してサクッと作ってみた。

環境

  • PHP 7.3.18
  • composer 1.10.10
  • Windows10 Home
  • localhost

利用するもの

作成手順

  • 任意のディレクトリに「QRコード」フォルダを作成
  • コマンドプロンプトを起動して、「QRコード」内に入る。
  • 下記を実行し、パッケージをインストールする。
composer require endroid/qr-code
  • 「QRコード」ディレクトリ直下にindex.phpを作成し、下記のコードを貼り付ける。
<?php
require_once __DIR__ . '/vendor/autoload.php';

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('Life is too short to be generating QR codes');

header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
  • 下記を実行し、ローカルサーバーを立ち上げる。
php -S localhost:8080

補足

composerでパッケージをインストールした際、私の環境では下記のエラーが表示された。

  Problem 1
    - endroid/qr-code 3.9.1 requires ext-gd * -> the requested PHP extension gd is missing from your system.
    - endroid/qr-code 3.9.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
                                           ode ^3.9 -> satisfiable by endroid/qr-code[3.9.0, 3.9.1].
  To enable extensions, verify that they are enabled in your .ini files:              e enabled in your .ini files:
    - C:\bin\php\php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.nal to see which files are used by PHP in CLI mode.

JPEG,PNG,GIFなどの画像処理をする際に利用するgdというextensionが必要とのこと。
php.iniの該当箇所がコメントアウトされていたので有効にしたらインストールができるようになった。

extension=gd2   ← ';'を消して保存すればOK
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0