0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

endroid/qr-codeを用いてphpでQRコード画像を生成する

Last updated at Posted at 2022-07-18

実現したいこと

phpのController内で任意の情報を持たせたQRコード画像を生成・保存する。

インストール

composer require endroid/qr-code

実装

$qrDataにはQRコードの中に保持させたいデータを入れておく。

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
use Endroid\QrCode\Label\Alignment\LabelAlignmentCenter;
use Endroid\QrCode\Label\Font\NotoSans;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Color\Color;

~~
$qrCode = Builder::create()
          ->writer(new PngWriter())
          ->writerOptions([])
          ->data($qrData)
          ->encoding(new Encoding('UTF-8'))
          ->errorCorrectionLevel(new ErrorCorrectionLevelHigh())
          ->size(200)
          ->margin(10)
          ->roundBlockSizeMode(new RoundBlockSizeModeMargin())
          ->build();
                    
$qrCode->saveToFile('filepath/qrCode.png');


0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?