test ettim, çalıştı. isteğe bağlı php dosyası içindeki Örnek Metin kısmını form alanına da ekleyebilirsin, daha fazla özelleştirme yapabilirsin.
buyur:
chillerlan/php-qrcode kütüphanesini projenize ekleyin:
composer require chillerlan/php-qrcode
ardından index.html içeriği;
<form action="qr_generator.php" method="post" enctype="multipart/form-data">
<input type="file" name="logo" accept="image/*">
<input type="submit" name="submit" value="QR Kodu Oluştur">
</form>qr_generator.php içeriği;
<?php
require_once 'vendor/autoload.php';
use chillerlan\QRCode\{QRCode, QROptions};
function createQRCode($text, $logoPath = null) {
$options = new QROptions([
'version' => 5,
'outputType' => QRCode::OUTPUT_IMAGE_PNG,
'eccLevel' => QRCode::ECC_L,
'scale' => 5,
'imageBase64' => false,
]);
// QR Kodu oluştur
$qrCode = (new QRCode($options))->render($text);
$qrCodeResource = imagecreatefromstring($qrCode);
if ($logoPath) {
$logo = imagecreatefromstring(file_get_contents($logoPath));
$qrWidth = imagesx($qrCodeResource);
$qrHeight = imagesy($qrCodeResource);
$logoWidth = imagesx($logo);
$logoHeight = imagesy($logo);
// Logo boyutlarını ve pozisyonunu ayarla
$logo_qr_width = $qrWidth/5;
$scale = $logoWidth/$logo_qr_width;
$logo_qr_height = $logoHeight/$scale;
imagecopyresampled($qrCodeResource, $logo, $qrWidth/2 - $logo_qr_width/2, $qrHeight/2 - $logo_qr_height/2, 0, 0, $logo_qr_width, $logo_qr_height, $logoWidth, $logoHeight);
}
// QR kodunu kaydet ve yolu döndür
$outputPath = 'qr_codes/qr_code.png';
imagepng($qrCodeResource, $outputPath);
imagedestroy($qrCodeResource);
if ($logoPath) {
imagedestroy($logo);
}
return $outputPath;
}
if (isset($_FILES['logo']) && $_FILES['logo']['error'] == 0) {
$logoPath = 'uploads/' . basename($_FILES['logo']['name']);
move_uploaded_file($_FILES['logo']['tmp_name'], $logoPath);
$qrPath = createQRCode('Örnek Metin', $logoPath);
} else {
$qrPath = createQRCode('Örnek Metin');
}
echo "<img src='$qrPath' />";
?>