Reading: indFlags.php.txt
← Back
<?php
$format = isset($_GET['format']) && $_GET['format'] === 'jpg' ? 'jpg' : 'png';
// 1. Double the resolution for a "Huge" feel (1200x800)
$width = 1251;
$height = 838;
$image = imagecreatetruecolor($width, $height);
$red = imagecolorallocate($image, 255, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, $width, ($height/2)-1, $red);
imagefilledrectangle($image, 0, $height/2, $width, $height, $white);
// 2. Silent Local Copy & Resize Logic
$localFile = 'Pancasila.png';
$logoUrl = "https://download.setneg.go.id/download/NotYetUploadbySetneg/logo/Pancasila.png";
if (!file_exists($localFile)) {
$ch = curl_init($logoUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$logoData = curl_exec($ch);
curl_close($ch);
if ($logoData) {
$tempGaruda = imagecreatefromstring($logoData);
if ($tempGaruda) {
$origW = imagesx($tempGaruda); $origH = imagesy($tempGaruda);
$saveH = 251; // Doubled your 251 requirement for the bigger flag
$saveW = ($origW / $origH) * $saveH;
$resizedCanvas = imagecreatetruecolor($saveW, $saveH);
imagealphablending($resizedCanvas, false);
imagesavealpha($resizedCanvas, true);
$transparent = imagecolorallocatealpha($resizedCanvas, 0, 0, 0, 127);
imagefill($resizedCanvas, 0, 0, $transparent);
imagecopyresampled($resizedCanvas, $tempGaruda, 0, 0, 0, 0, $saveW, $saveH, $origW, $origH);
imagepng($resizedCanvas, $localFile);
imagedestroy($tempGaruda); imagedestroy($resizedCanvas);
}
}
}
// 3. Merge Resized Logo
if (file_exists($localFile)) {
$garuda = imagecreatefrompng($localFile);
if ($garuda) {
$gWidth = imagesx($garuda); $gHeight = imagesy($garuda);
$centerX = ($width - $gWidth) / 2;
$centerY = ($height - $gHeight) / 2;
imagealphablending($image, true);
imagecopy($image, $garuda, $centerX, $centerY, 0, 0, $gWidth, $gHeight);
imagedestroy($garuda);
}
}
// 4. Output
if ($format === 'jpg') {
header('Content-Type: image/jpeg');
header('Content-Disposition: attachment; filename="Indonesia_flags.jpg"');
imagejpeg($image, NULL, 100); // Max quality
} else {
header('Content-Type: image/png');
imagepng($image);
}
imagedestroy($image);
?>