Add logo path function and enhance logo image creation for QR key chains

This commit introduces a new function to define the logo path for QR key chains and enhances the image creation process by adding functionality to load, resize, and center the logo within a specified size. If the logo file is missing, a fallback to a text drawing is implemented. These changes improve the visual presentation of QR codes with logos.
This commit is contained in:
2026-07-11 18:53:02 -04:00
parent 33706bb195
commit 54a7e1dae9
2 changed files with 51 additions and 1 deletions

BIN
images/ms1-kc-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -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);