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:
@@ -23,7 +23,7 @@ rsync -av backend/url-shortener/ alpine-be:/var/www/localhost/htdocs/apps/s/
|
|||||||
cd /var/www/.../androidcast_project/android_cast
|
cd /var/www/.../androidcast_project/android_cast
|
||||||
php81 examples/crash_reporter/backend/scripts/ensure_url_shortener_prod_config.php
|
php81 examples/crash_reporter/backend/scripts/ensure_url_shortener_prod_config.php
|
||||||
|
|
||||||
apk add libqrencode-tools # QR PNG (/api/v1/qr/…)
|
apk add libqrencode-tools php83-gd # QR PNG (/api/v1/qr/…) + logo overlay
|
||||||
rc-service php-fpm81 restart
|
rc-service php-fpm81 restart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 8.2 KiB |
@@ -3,8 +3,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
/** Branded QR PNG: high error correction + centered app logo with white border. */
|
/** Branded QR PNG: high error correction + centered app logo with white border. */
|
||||||
final class QrBrandedRenderer {
|
final class QrBrandedRenderer {
|
||||||
private const LOGO_FRACTION = 0.22;
|
private const LOGO_FRACTION = 0.24;
|
||||||
private const BORDER_FRACTION = 0.045;
|
private const BORDER_FRACTION = 0.05;
|
||||||
|
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,36 @@ final class QrBrandedRenderer {
|
|||||||
return $branded ?? $raw;
|
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> */
|
/** @return list<string> */
|
||||||
private static function logoCandidates(): array {
|
private static function logoCandidates(): array {
|
||||||
return [
|
$paths = [];
|
||||||
dirname(__DIR__) . '/assets/ac_qr_logo.png',
|
$env = getenv('AC_QR_LOGO_PATH');
|
||||||
__DIR__ . '/../assets/ac_qr_logo.png',
|
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 {
|
private static function logoPath(): ?string {
|
||||||
@@ -71,7 +95,7 @@ final class QrBrandedRenderer {
|
|||||||
if ($qr === false) {
|
if ($qr === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$logo = @imagecreatefrompng($logoPath);
|
$logo = self::loadLogoImage($logoPath);
|
||||||
if ($logo === false) {
|
if ($logo === false) {
|
||||||
imagedestroy($qr);
|
imagedestroy($qr);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user