Deploy: 2026-05-23 18:37:08

This commit is contained in:
Hamza-Ayed
2026-05-23 18:37:08 +03:00
parent 3b42dc64a9
commit 03ece01f98
2 changed files with 57 additions and 18 deletions

View File

@@ -1,28 +1,59 @@
<?php
header('Content-Type: application/json');
$fontDir = __DIR__ . '/../fonts';
$roboto = $fontDir . '/Roboto-Bold.ttf';
$lora = $fontDir . '/Lora-Bold.ttf';
// Capture PHP errors/warnings
$errors = [];
set_error_handler(function($errno, $errstr, $errfile, $errline) use (&$errors) {
$errors[] = [
'level' => $errno,
'message' => $errstr,
'file' => $errfile,
'line' => $errline
];
return true;
});
$results = [];
require_once __DIR__ . '/../includes/WhatsApp.php';
// Trigger download if any fonts are missing
try {
WhatsAppClient::generateOtpImageBase64('123');
} catch (\Throwable $e) {
$errors[] = ['exception' => $e->getMessage()];
}
$fontDir = realpath(__DIR__ . '/../fonts');
$roboto = $fontDir ? $fontDir . '/Roboto-Bold.ttf' : '';
$lora = $fontDir ? $fontDir . '/Lora-Bold.ttf' : '';
$results = [
'font_dir' => $fontDir,
'roboto_path' => $roboto,
'lora_path' => $lora,
'roboto_exists' => file_exists($roboto),
'lora_exists' => file_exists($lora),
'php_errors_during_init' => $errors
];
// Reset captured errors for rendering phase
$errors = [];
$im = imagecreatetruecolor(100, 100);
$color = imagecolorallocate($im, 0, 0, 0);
function testFont($im, $fontPath, $color) {
if (!file_exists($fontPath)) {
if (!$fontPath || !file_exists($fontPath)) {
return ['error' => 'File does not exist'];
}
$fontResults = [];
for ($i = 0; $i <= 9; $i++) {
// Attempt to render the digit using imagettftext
$res = @imagettftext($im, 12, 0, 10, 50, $color, $fontPath, (string)$i);
// Run WITHOUT @ to trigger the error handler
$res = imagettftext($im, 12, 0, 10, 50, $color, $fontPath, (string)$i);
if ($res === false) {
$fontResults[$i] = 'Failed (returned false)';
$fontResults[$i] = 'Failed';
} else {
$fontResults[$i] = 'Success: ' . json_encode($res);
$fontResults[$i] = 'Success';
}
}
return $fontResults;
@@ -30,6 +61,7 @@ function testFont($im, $fontPath, $color) {
$results['Roboto-Bold.ttf'] = testFont($im, $roboto, $color);
$results['Lora-Bold.ttf'] = testFont($im, $lora, $color);
$results['rendering_errors'] = $errors;
imagedestroy($im);

View File

@@ -108,6 +108,11 @@ class WhatsAppClient {
if (!is_dir($fontDir)) {
@mkdir($fontDir, 0755, true);
}
$fontDir = realpath($fontDir);
if (!$fontDir) {
return;
}
$fonts = [
'Roboto-Bold.ttf' => 'https://github.com/google/fonts/raw/main/apache/roboto/static/Roboto-Bold.ttf',
@@ -166,15 +171,17 @@ class WhatsAppClient {
$useTtf = false;
$availableFonts = [];
if (function_exists('imagettftext')) {
$fontDir = __DIR__ . '/../fonts';
if (file_exists($fontDir . '/Roboto-Bold.ttf') && @filesize($fontDir . '/Roboto-Bold.ttf') > 20000) {
$availableFonts[] = $fontDir . '/Roboto-Bold.ttf';
}
if (file_exists($fontDir . '/Lora-Bold.ttf') && @filesize($fontDir . '/Lora-Bold.ttf') > 20000) {
$availableFonts[] = $fontDir . '/Lora-Bold.ttf';
}
if (!empty($availableFonts)) {
$useTtf = true;
$fontDir = realpath(__DIR__ . '/../fonts');
if ($fontDir) {
if (file_exists($fontDir . '/Roboto-Bold.ttf') && @filesize($fontDir . '/Roboto-Bold.ttf') > 20000) {
$availableFonts[] = $fontDir . '/Roboto-Bold.ttf';
}
if (file_exists($fontDir . '/Lora-Bold.ttf') && @filesize($fontDir . '/Lora-Bold.ttf') > 20000) {
$availableFonts[] = $fontDir . '/Lora-Bold.ttf';
}
if (!empty($availableFonts)) {
$useTtf = true;
}
}
}