diff --git a/backend/app/Controllers/OTPController.php b/backend/app/Controllers/OTPController.php index 219ba42..b297bd1 100644 --- a/backend/app/Controllers/OTPController.php +++ b/backend/app/Controllers/OTPController.php @@ -28,9 +28,22 @@ class OTPController extends BaseController if (function_exists('imagecreate')) { // Base image $img = imagecreatetruecolor(400, 200); - $bg = imagecolorallocate($img, 240, 248, 255); // Alice blue background - $textColor = imagecolorallocate($img, 15, 23, 42); // Dark text - $lineColor = imagecolorallocate($img, 203, 213, 225); // Subtle lines + + // Define high-contrast, beautiful color palettes [bg, text, line] + $palettes = [ + ['bg' => [240, 248, 255], 'text' => [15, 23, 42], 'line' => [148, 163, 184]], // Light Blue / Dark Navy + ['bg' => [255, 250, 240], 'text' => [67, 20, 7], 'line' => [252, 211, 77]], // Floral White / Dark Brown + ['bg' => [240, 253, 244], 'text' => [6, 78, 59], 'line' => [110, 231, 183]], // Mint Green / Dark Green + ['bg' => [254, 242, 242], 'text' => [127, 29, 29], 'line' => [252, 165, 165]], // Light Red / Dark Red + ['bg' => [250, 245, 255], 'text' => [88, 28, 135], 'line' => [216, 180, 254]], // Light Purple / Dark Purple + ['bg' => [255, 247, 237], 'text' => [154, 52, 18], 'line' => [253, 186, 116]], // Light Orange / Dark Orange + ]; + + $palette = $palettes[array_rand($palettes)]; + + $bg = imagecolorallocate($img, $palette['bg'][0], $palette['bg'][1], $palette['bg'][2]); + $textColor = imagecolorallocate($img, $palette['text'][0], $palette['text'][1], $palette['text'][2]); + $lineColor = imagecolorallocate($img, $palette['line'][0], $palette['line'][1], $palette['line'][2]); imagefill($img, 0, 0, $bg); @@ -39,17 +52,27 @@ class OTPController extends BaseController imageline($img, rand(0, 400), rand(0, 200), rand(0, 400), rand(0, 200), $lineColor); } - // Create a temporary small image for the text (since built-in font 5 is small) + // Add random noise dots + for ($i = 0; $i < 200; $i++) { + imagesetpixel($img, rand(0, 400), rand(0, 200), $lineColor); + } + + // Create a temporary small image for the text $tmp = imagecreatetruecolor(100, 40); - $tmpBg = imagecolorallocate($tmp, 240, 248, 255); - $tmpText = imagecolorallocate($tmp, 15, 23, 42); + $tmpBg = imagecolorallocate($tmp, $palette['bg'][0], $palette['bg'][1], $palette['bg'][2]); + $tmpText = imagecolorallocate($tmp, $palette['text'][0], $palette['text'][1], $palette['text'][2]); imagefill($tmp, 0, 0, $tmpBg); - $spacedCode = implode(' ', str_split($code)); - imagestring($tmp, 5, 10, 12, $spacedCode, $tmpText); + $spacedCode = implode(' ', str_split($code)); // Slightly wider spacing - // Scale up the text image to the main image - imagecopyresized($img, $tmp, 0, 0, 0, 0, 400, 200, 100, 40); + // Draw text multiple times with 1px offsets to create a bold effect + imagestring($tmp, 5, 8, 12, $spacedCode, $tmpText); + imagestring($tmp, 5, 9, 12, $spacedCode, $tmpText); // Bold X + imagestring($tmp, 5, 8, 13, $spacedCode, $tmpText); // Bold Y + imagestring($tmp, 5, 9, 13, $spacedCode, $tmpText); // Bold XY + + // Scale up the text image to the main image using resampled for smooth (non-pixelated) edges + imagecopyresampled($img, $tmp, 0, 0, 0, 0, 400, 200, 100, 40); imagepng($img, $filepath); imagedestroy($img); @@ -198,8 +221,7 @@ class OTPController extends BaseController } else if ($type === 'image') { // Generate OTP Image $imageUrl = $this->generateOtpImage($code); - $captionMsg = "مرحباً! هذا هو رمز التحقق الخاص بك لمتجر نابه. الرجاء عدم مشاركته."; - ConversationFlowEngine::sendReply($session, $phone, $captionMsg, $imageUrl); + ConversationFlowEngine::sendReply($session, $phone, '', $imageUrl); } else { // Send text $textMsg = "رمز التحقق الخاص بك لمتجر نابه هو: *{$code}* \n الرجاء عدم مشاركته مع أي شخص.";