=2 && $y<=4 && $x>=2 && $x<=4)); $m[$pos[1]+$y][$pos[0]+$x] = $on ? 1 : 0; } } // Separator for ($i = -1; $i < 8; $i++) { if ($pos[1]+$i >= 0 && $pos[1]+$i < $size && $pos[0]-1 >= 0) $m[$pos[1]+$i][$pos[0]-1] = 0; if ($pos[1]-1 >= 0 && $pos[0]+$i >= 0 && $pos[0]+$i < $size) $m[$pos[1]-1][$pos[0]+$i] = 0; } } // Timing patterns for ($i = 8; $i < $size - 8; $i++) { $m[6][$i] = ($i % 2 == 0) ? 1 : 0; $m[$i][6] = ($i % 2 == 0) ? 1 : 0; } // Data area (pseudo-random but consistent — actual QR needs real algorithm) // Ye ek simplified version hai jo visuals ke liye hai $seed = crc32(implode(',', $bytes)); mt_srand($seed); for ($y = 0; $y < $size; $y++) { for ($x = 0; $x < $size; $x++) { if (qr_is_reserved($x, $y, $size)) continue; $m[$y][$x] = mt_rand(0, 1); } } return $m; } function qr_is_reserved($x, $y, $size) { // Finder patterns if ($x < 9 && $y < 9) return true; if ($x >= $size-8 && $y < 9) return true; if ($x < 9 && $y >= $size-8) return true; // Timing if ($x == 6 || $y == 6) return true; return false; } function qr_is_dark($m, $x, $y, $size) { if ($x < 0 || $x >= $size || $y < 0 || $y >= $size) return false; return $m[$y][$x] == 1; } // ============================================================ // MAIN PROCESSING // ============================================================ $links_input = $_POST['links'] ?? ''; $generated = []; if (!empty($links_input)) { $links = array_filter(array_map('trim', explode("\n", $links_input))); foreach ($links as $link) { $parts = explode('/', parse_url($link, PHP_URL_PATH)); $id = str_replace('.pdf', '', end($parts)); // Simple reliable QR (using external fallback API) // Pahle local try karo, agar fail ho to API use karo $qr_url = 'https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=' . urlencode($link); $qr_data = @file_get_contents($qr_url); if ($qr_data && strlen($qr_data) > 500) { // Save basic QR $basic_file = "$output_folder/{$id}_basic.png"; file_put_contents($basic_file, $qr_data); // Ab isko GD se enhance karo (dots + logo) $img = @imagecreatefromstring($qr_data); if ($img) { $w = imagesx($img); $h = imagesy($img); // Naya image with dots style $new_size = 600; $final = imagecreatetruecolor($new_size + 40, $new_size + 100); $white = imagecolorallocate($final, 255, 255, 255); $black = imagecolorallocate($final, 0, 0, 0); imagefill($final, 0, 0, $white); // Border imagerectangle($final, 0, 0, $new_size + 39, $new_size + 39, $black); imagerectangle($final, 1, 1, $new_size + 38, $new_size + 38, $black); imagerectangle($final, 2, 2, $new_size + 37, $new_size + 37, $black); imagerectangle($final, 3, 3, $new_size + 36, $new_size + 36, $black); // QR ko dots style mein convert karo $module_count = 29; // approximate $scale = $new_size / $module_count; for ($y = 0; $y < $module_count; $y++) { for ($x = 0; $x < $module_count; $x++) { // Sample pixel from original QR $sx = intval($x * $w / $module_count); $sy = intval($y * $h / $module_count); $rgb = imagecolorat($img, $sx, $sy); $r = ($rgb >> 16) & 0xFF; if ($r < 128) { $px = 20 + $x * $scale; $py = 20 + $y * $scale; imagefilledellipse($final, $px + $scale/2, $py + $scale/2, $scale*0.85, $scale*0.85, $black); } } } // Logo add karo center mein $logo_path = __DIR__ . '/icon/mofa.png'; if (file_exists($logo_path)) { $logo = @imagecreatefrompng($logo_path); if ($logo) { $lw = imagesx($logo); $lh = imagesy($logo); $lsize = intval($new_size * 0.22); // White bg imagefilledrectangle($final, ($new_size-$lsize)/2 + 20 - 5, ($new_size-$lsize)/2 + 20 - 5, ($new_size+$lsize)/2 + 20 + 5, ($new_size+$lsize)/2 + 20 + 5, $white); imagecopyresampled($final, $logo, 20 + ($new_size - $lsize) / 2, 20 + ($new_size - $lsize) / 2, 0, 0, $lsize, $lsize, $lw, $lh); imagedestroy($logo); } } // Text below $font = 5; $text1 = "Ministry of Foreign Affairs Pakistan"; $text2 = $id; $tw1 = imagefontwidth($font) * strlen($text1); $tw2 = imagefontwidth($font) * strlen($text2); imagestring($final, $font, ($new_size+40-$tw1)/2, $new_size + 50, $text1, $black); imagestring($final, $font, ($new_size+40-$tw2)/2, $new_size + 70, $text2, $black); // Save final imagepng($final, "$output_folder/{$id}.png"); imagedestroy($final); imagedestroy($img); $generated[] = $id; // Delete basic @unlink($basic_file); } } } } ?>
Har line par ek link paste karein: