82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
// 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;
|
|
});
|
|
|
|
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' : '';
|
|
$cairo = $fontDir ? $fontDir . '/Cairo-Bold.ttf' : '';
|
|
|
|
$results = [
|
|
'font_dir' => $fontDir,
|
|
'roboto_path' => $roboto,
|
|
'lora_path' => $lora,
|
|
'cairo_path' => $cairo,
|
|
'roboto_exists' => file_exists($roboto),
|
|
'lora_exists' => file_exists($lora),
|
|
'cairo_exists' => file_exists($cairo),
|
|
'php_errors_during_init' => $errors
|
|
];
|
|
|
|
// Reset captured errors for rendering phase
|
|
$errors = [];
|
|
|
|
$im = imagecreatetruecolor(200, 200);
|
|
$color = imagecolorallocate($im, 0, 0, 0);
|
|
|
|
function testFontDigits($im, $fontPath, $color) {
|
|
if (!$fontPath || !file_exists($fontPath)) {
|
|
return ['error' => 'File does not exist'];
|
|
}
|
|
|
|
$fontResults = [];
|
|
for ($i = 0; $i <= 9; $i++) {
|
|
$res = imagettftext($im, 12, 0, 10, 50, $color, $fontPath, (string)$i);
|
|
if ($res === false) {
|
|
$fontResults[$i] = 'Failed';
|
|
} else {
|
|
$fontResults[$i] = 'Success';
|
|
}
|
|
}
|
|
return $fontResults;
|
|
}
|
|
|
|
$results['Roboto-Bold.ttf_digits'] = testFontDigits($im, $roboto, $color);
|
|
$results['Lora-Bold.ttf_digits'] = testFontDigits($im, $lora, $color);
|
|
$results['Cairo-Bold.ttf_digits'] = testFontDigits($im, $cairo, $color);
|
|
|
|
// Test Arabic text rendering specifically for Cairo
|
|
if ($cairo && file_exists($cairo)) {
|
|
$res = imagettftext($im, 14, 0, 10, 100, $color, $cairo, 'ﻖﻘﺤﺘﻠﺎ ﺰﻣﺮ'); // رمز التحقق (RTL shaped)
|
|
$results['Cairo-Bold.ttf_arabic_render'] = ($res === false) ? 'Failed' : 'Success';
|
|
} else {
|
|
$results['Cairo-Bold.ttf_arabic_render'] = 'File not found';
|
|
}
|
|
|
|
$results['rendering_errors'] = $errors;
|
|
|
|
imagedestroy($im);
|
|
|
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
|
?>
|