diff --git a/images/ms1-kc-logo.png b/images/ms1-kc-logo.png new file mode 100644 index 0000000..a2f22bc Binary files /dev/null and b/images/ms1-kc-logo.png differ diff --git a/php/inc_fx_kc_qr.php b/php/inc_fx_kc_qr.php index fc1c683..4c57dd3 100644 --- a/php/inc_fx_kc_qr.php +++ b/php/inc_fx_kc_qr.php @@ -3,10 +3,60 @@ require_once __DIR__ . '/../libs/phpqrcode-master/qrlib.php'; /** - * Logo MS1 au centre du QR (carré noir, texte blanc). + * Chemin du logo MS1 pour le centre des QR key_chain. + */ +function fxKcQrLogoPath() +{ + return __DIR__ . '/../images/ms1-kc-logo.png'; +} + +/** + * Charge et redimensionne le logo PNG (carré de sortie $intSize). + * Repli : dessin texte si le fichier est absent. */ function fxKcQrCreateLogoImage($intSize) { + $intSize = max(24, (int) $intSize); + $strLogoPath = fxKcQrLogoPath(); + + if (is_file($strLogoPath)) { + $imgSrc = @imagecreatefrompng($strLogoPath); + if ($imgSrc !== false) { + $intSrcW = imagesx($imgSrc); + $intSrcH = imagesy($imgSrc); + $img = imagecreatetruecolor($intSize, $intSize); + imagealphablending($img, false); + imagesavealpha($img, true); + $colTransparent = imagecolorallocatealpha($img, 0, 0, 0, 127); + imagefilledrectangle($img, 0, 0, $intSize, $intSize, $colTransparent); + imagealphablending($img, true); + + // Conserve le ratio (158×180) dans le carré cible. + $fltScale = min($intSize / max(1, $intSrcW), $intSize / max(1, $intSrcH)); + $intDstW = max(1, (int) round($intSrcW * $fltScale)); + $intDstH = max(1, (int) round($intSrcH * $fltScale)); + $intDstX = (int) floor(($intSize - $intDstW) / 2); + $intDstY = (int) floor(($intSize - $intDstH) / 2); + + imagecopyresampled( + $img, + $imgSrc, + $intDstX, + $intDstY, + 0, + 0, + $intDstW, + $intDstH, + $intSrcW, + $intSrcH + ); + imagedestroy($imgSrc); + + return $img; + } + } + + // Repli : dessin texte (si PNG manquant). $img = imagecreatetruecolor($intSize, $intSize); imagealphablending($img, true); imagesavealpha($img, true);