Deploy: 2026-05-23 18:56:57
This commit is contained in:
@@ -25,23 +25,20 @@ try {
|
|||||||
$fontDir = realpath(__DIR__ . '/../fonts');
|
$fontDir = realpath(__DIR__ . '/../fonts');
|
||||||
$roboto = $fontDir ? $fontDir . '/Roboto-Bold.ttf' : '';
|
$roboto = $fontDir ? $fontDir . '/Roboto-Bold.ttf' : '';
|
||||||
$lora = $fontDir ? $fontDir . '/Lora-Bold.ttf' : '';
|
$lora = $fontDir ? $fontDir . '/Lora-Bold.ttf' : '';
|
||||||
$cairo = $fontDir ? $fontDir . '/Cairo-Bold.ttf' : '';
|
|
||||||
|
|
||||||
$results = [
|
$results = [
|
||||||
'font_dir' => $fontDir,
|
'font_dir' => $fontDir,
|
||||||
'roboto_path' => $roboto,
|
'roboto_path' => $roboto,
|
||||||
'lora_path' => $lora,
|
'lora_path' => $lora,
|
||||||
'cairo_path' => $cairo,
|
|
||||||
'roboto_exists' => file_exists($roboto),
|
'roboto_exists' => file_exists($roboto),
|
||||||
'lora_exists' => file_exists($lora),
|
'lora_exists' => file_exists($lora),
|
||||||
'cairo_exists' => file_exists($cairo),
|
|
||||||
'php_errors_during_init' => $errors
|
'php_errors_during_init' => $errors
|
||||||
];
|
];
|
||||||
|
|
||||||
// Reset captured errors for rendering phase
|
// Reset captured errors for rendering phase
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
$im = imagecreatetruecolor(200, 200);
|
$im = imagecreatetruecolor(100, 100);
|
||||||
$color = imagecolorallocate($im, 0, 0, 0);
|
$color = imagecolorallocate($im, 0, 0, 0);
|
||||||
|
|
||||||
function testFontDigits($im, $fontPath, $color) {
|
function testFontDigits($im, $fontPath, $color) {
|
||||||
@@ -63,15 +60,6 @@ function testFontDigits($im, $fontPath, $color) {
|
|||||||
|
|
||||||
$results['Roboto-Bold.ttf_digits'] = testFontDigits($im, $roboto, $color);
|
$results['Roboto-Bold.ttf_digits'] = testFontDigits($im, $roboto, $color);
|
||||||
$results['Lora-Bold.ttf_digits'] = testFontDigits($im, $lora, $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;
|
$results['rendering_errors'] = $errors;
|
||||||
|
|
||||||
|
|||||||
@@ -117,8 +117,7 @@ class WhatsAppClient {
|
|||||||
// Use Fontsource dedicated jsDelivr CDN endpoint for direct TTF files
|
// Use Fontsource dedicated jsDelivr CDN endpoint for direct TTF files
|
||||||
$fonts = [
|
$fonts = [
|
||||||
'Roboto-Bold.ttf' => 'https://cdn.jsdelivr.net/fontsource/fonts/roboto@latest/latin-700-normal.ttf',
|
'Roboto-Bold.ttf' => 'https://cdn.jsdelivr.net/fontsource/fonts/roboto@latest/latin-700-normal.ttf',
|
||||||
'Lora-Bold.ttf' => 'https://cdn.jsdelivr.net/fontsource/fonts/lora@latest/latin-700-normal.ttf',
|
'Lora-Bold.ttf' => 'https://cdn.jsdelivr.net/fontsource/fonts/lora@latest/latin-700-normal.ttf'
|
||||||
'Cairo-Bold.ttf' => 'https://cdn.jsdelivr.net/fontsource/fonts/cairo@latest/arabic-700-normal.ttf'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($fonts as $filename => $url) {
|
foreach ($fonts as $filename => $url) {
|
||||||
@@ -189,7 +188,6 @@ class WhatsAppClient {
|
|||||||
// --- 1. Check if TTF is available and fonts are loaded ---
|
// --- 1. Check if TTF is available and fonts are loaded ---
|
||||||
$useTtf = false;
|
$useTtf = false;
|
||||||
$availableFonts = [];
|
$availableFonts = [];
|
||||||
$arabicFont = '';
|
|
||||||
if (function_exists('imagettftext')) {
|
if (function_exists('imagettftext')) {
|
||||||
$fontDir = realpath(__DIR__ . '/../fonts');
|
$fontDir = realpath(__DIR__ . '/../fonts');
|
||||||
if ($fontDir) {
|
if ($fontDir) {
|
||||||
@@ -199,11 +197,6 @@ class WhatsAppClient {
|
|||||||
if (file_exists($fontDir . '/Lora-Bold.ttf') && @filesize($fontDir . '/Lora-Bold.ttf') > 20000) {
|
if (file_exists($fontDir . '/Lora-Bold.ttf') && @filesize($fontDir . '/Lora-Bold.ttf') > 20000) {
|
||||||
$availableFonts[] = $fontDir . '/Lora-Bold.ttf';
|
$availableFonts[] = $fontDir . '/Lora-Bold.ttf';
|
||||||
}
|
}
|
||||||
if (file_exists($fontDir . '/Cairo-Bold.ttf') && @filesize($fontDir . '/Cairo-Bold.ttf') > 20000) {
|
|
||||||
$arabicFont = $fontDir . '/Cairo-Bold.ttf';
|
|
||||||
// We can also use Cairo for drawing OTP digits for extra variety!
|
|
||||||
$availableFonts[] = $fontDir . '/Cairo-Bold.ttf';
|
|
||||||
}
|
|
||||||
if (!empty($availableFonts)) {
|
if (!empty($availableFonts)) {
|
||||||
$useTtf = true;
|
$useTtf = true;
|
||||||
}
|
}
|
||||||
@@ -267,51 +260,32 @@ class WhatsAppClient {
|
|||||||
|
|
||||||
// --- 3. Draw Random Header Label with Variable Font ---
|
// --- 3. Draw Random Header Label with Variable Font ---
|
||||||
$labels = [
|
$labels = [
|
||||||
// English labels of varying word count
|
'Verification Code:',
|
||||||
['text' => 'Verification Code:', 'lang' => 'en'],
|
'Your OTP:',
|
||||||
['text' => 'Your OTP:', 'lang' => 'en'],
|
'Security Key:',
|
||||||
['text' => 'Security Key:', 'lang' => 'en'],
|
'Access Number:',
|
||||||
['text' => 'Access Number:', 'lang' => 'en'],
|
'Auth Code:',
|
||||||
['text' => 'Auth Code:', 'lang' => 'en'],
|
'Login Pin:',
|
||||||
['text' => 'Login Pin:', 'lang' => 'en'],
|
'Secret Key:',
|
||||||
['text' => 'Secret Key:', 'lang' => 'en'],
|
'Your Number:',
|
||||||
['text' => 'Your Number:', 'lang' => 'en'],
|
'One Time Pass:',
|
||||||
['text' => 'One Time Pass:', 'lang' => 'en'],
|
'Code:',
|
||||||
['text' => 'Code:', 'lang' => 'en'],
|
'App Verification PIN:',
|
||||||
['text' => 'App Verification PIN:', 'lang' => 'en'],
|
'System Access Key:',
|
||||||
['text' => 'System Access Key:', 'lang' => 'en'],
|
'Dynamic Access PIN:',
|
||||||
['text' => 'Dynamic Access PIN:', 'lang' => 'en'],
|
'Secure Verification Code:',
|
||||||
['text' => 'Secure Verification Code:', 'lang' => 'en'],
|
'Account Code:',
|
||||||
['text' => 'Account Code:', 'lang' => 'en'],
|
'Secure Passcode:'
|
||||||
['text' => 'Secure Passcode:', 'lang' => 'en'],
|
|
||||||
|
|
||||||
// Pre-shaped Arabic labels (written RTL for GD engine)
|
|
||||||
['text' => 'ﻖﻘﺤﺘﻠﺎ ﺰﻣﺮ', 'lang' => 'ar'], // رمز التحقق
|
|
||||||
['text' => 'ﻥﺎﻣﺃﻟﺍ ﺩﻮﻛ', 'lang' => 'ar'], // كود الأمان
|
|
||||||
['text' => 'ﺪﻴﻜﺃﺘﻠﺍ ﺰﻣﺮ', 'lang' => 'ar'], // رمز التأكيد
|
|
||||||
['text' => 'ﻒﻳﺮﻌﺘﻟﺍ ﻢﻗﺭ', 'lang' => 'ar'] // رقم التعريف
|
|
||||||
];
|
];
|
||||||
|
$label = $labels[array_rand($labels)];
|
||||||
$selectedLabel = $labels[array_rand($labels)];
|
|
||||||
$label = $selectedLabel['text'];
|
|
||||||
|
|
||||||
if ($useTtf) {
|
if ($useTtf) {
|
||||||
// Select font: Cairo-Bold for Arabic, random for English
|
$labelFont = $availableFonts[array_rand($availableFonts)];
|
||||||
$labelFont = ($selectedLabel['lang'] === 'ar' && $arabicFont)
|
|
||||||
? $arabicFont
|
|
||||||
: $availableFonts[array_rand($availableFonts)];
|
|
||||||
|
|
||||||
// Draw smooth TTF label (y=28 is baseline position, roughly equivalent to y=10 box)
|
// Draw smooth TTF label (y=28 is baseline position, roughly equivalent to y=10 box)
|
||||||
$size = ($selectedLabel['lang'] === 'ar') ? 14 : 12; // Adjust size for Arabic readability
|
imagettftext($im, 12, 0, 20, 28, $textColor, $labelFont, $label);
|
||||||
imagettftext($im, $size, 0, 20, 28, $textColor, $labelFont, $label);
|
|
||||||
} else {
|
} else {
|
||||||
// Fallback: draw using built-in font (convert Arabic to English fallback to avoid garbage text)
|
|
||||||
$fallbackLabel = $label;
|
|
||||||
if ($selectedLabel['lang'] === 'ar') {
|
|
||||||
$fallbackLabel = 'Verification Code:';
|
|
||||||
}
|
|
||||||
$labelFont = random_int(3, 5);
|
$labelFont = random_int(3, 5);
|
||||||
imagestring($im, $labelFont, 20, 10, $fallbackLabel, $textColor);
|
imagestring($im, $labelFont, 20, 10, $label, $textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a bounding border
|
// Draw a bounding border
|
||||||
|
|||||||
Reference in New Issue
Block a user