[amazon linux2] PHP7.4でQRコードを生成する

$ require endroid/qr-code
Problem 1
– endroid/qr-code[3.9.0, …, 3.9.3] require ext-gd * -> it is missing from your system. Install or enable PHP’s gd extension.

$ yum list | grep gd
php-gd.x86_64 7.4.11-1.amzn2 amzn2extra-php7.4

$ sudo yum install php-gd.x86_64
$ composer require endroid/qr-code

app.php

<?php
require_once(__DIR__.'/vendor/autoload.php');

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('hello qr code');

// header('Content-Type:'.$qrCode->getContentType());
// echo $qrCode->writeString();
$qrCode->writeFile(__DIR__.'/qrcode.png');

echoでブラウザで表示し、writeFileで画像を保存

OK, Let’s Go