mirror of
git://f0xx.org/ac/ac-ms-url-shortener
synced 2026-08-09 21:00:04 +03:00
Sync branded QR logo with platform-php updates.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,8 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
/** Branded QR PNG: high error correction + centered app logo with white border. */
|
||||
final class QrBrandedRenderer {
|
||||
private const LOGO_FRACTION = 0.22;
|
||||
private const BORDER_FRACTION = 0.045;
|
||||
private const LOGO_FRACTION = 0.24;
|
||||
private const BORDER_FRACTION = 0.05;
|
||||
|
||||
private function __construct() {
|
||||
}
|
||||
@@ -22,12 +22,36 @@ final class QrBrandedRenderer {
|
||||
return $branded ?? $raw;
|
||||
}
|
||||
|
||||
public static function dataUri(string $text, int $size = 256): ?string {
|
||||
$png = self::renderPng($text, $size);
|
||||
if ($png === null) {
|
||||
return null;
|
||||
}
|
||||
return 'data:image/png;base64,' . base64_encode($png);
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private static function logoCandidates(): array {
|
||||
return [
|
||||
dirname(__DIR__) . '/assets/ac_qr_logo.png',
|
||||
__DIR__ . '/../assets/ac_qr_logo.png',
|
||||
];
|
||||
$paths = [];
|
||||
$env = getenv('AC_QR_LOGO_PATH');
|
||||
if (is_string($env) && $env !== '') {
|
||||
$paths[] = $env;
|
||||
}
|
||||
$paths[] = dirname(__DIR__) . '/assets/ac_qr_logo.png';
|
||||
$paths[] = __DIR__ . '/../assets/ac_qr_logo.png';
|
||||
$paths[] = dirname(__DIR__, 2) . '/ac-platform-php/assets/ac_qr_logo.png';
|
||||
$paths[] = dirname(__DIR__, 2) . '/ac-platform-php/public/assets/ac_qr_logo.png';
|
||||
return $paths;
|
||||
}
|
||||
|
||||
/** @return \GdImage|false */
|
||||
private static function loadLogoImage(string $path) {
|
||||
$bytes = @file_get_contents($path);
|
||||
if (!is_string($bytes) || $bytes === '') {
|
||||
return false;
|
||||
}
|
||||
$img = @imagecreatefromstring($bytes);
|
||||
return $img !== false ? $img : false;
|
||||
}
|
||||
|
||||
private static function logoPath(): ?string {
|
||||
@@ -71,7 +95,7 @@ final class QrBrandedRenderer {
|
||||
if ($qr === false) {
|
||||
return null;
|
||||
}
|
||||
$logo = @imagecreatefrompng($logoPath);
|
||||
$logo = self::loadLogoImage($logoPath);
|
||||
if ($logo === false) {
|
||||
imagedestroy($qr);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user