> 24) return true; } } return false; } /* ------------- main logic ------------- */ $gifData = null; $fileExists = false; $showPreview = false; $finalName = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['image_url'])) { $url = filter_var(trim($_POST['image_url']), FILTER_VALIDATE_URL); $inputName = trim($_POST['filename'] ?? ''); if (!$url) { log_debug('❌ Invalid URL'); } else { log_debug('📥 Downloading: ' . $url); $imgBin = @file_get_contents($url); if ($imgBin === false) { log_debug('❌ Download failed'); } else { // Check if URL ends with .gif (case insensitive) $path = parse_url($url, PHP_URL_PATH); $isGif = strtolower(pathinfo($path, PATHINFO_EXTENSION)) === 'gif'; if ($isGif) { // Use downloaded GIF data directly without reprocessing $gifData = $imgBin; $base = $inputName ? pathinfo($inputName, PATHINFO_FILENAME) : pathinfo($path, PATHINFO_FILENAME); $finalName = $base . '.gif'; $showPreview = true; log_debug('ℹ️ Input is GIF — skipping re-encoding.'); } else { $src = @imagecreatefromstring($imgBin); if (!$src) { log_debug('❌ Unsupported/corrupt image'); } else { $w = imagesx($src); $h = imagesy($src); $hasAlpha = has_transparency($src); log_debug('🔍 Transparency: ' . ($hasAlpha ? 'yes' : 'no')); /* create truecolor canvas & copy */ $tmp = imagecreatetruecolor($w, $h); imagesavealpha($tmp, true); $transCol = imagecolorallocatealpha($tmp, 0, 0, 0, 127); imagefill($tmp, 0, 0, $transCol); imagecopy($tmp, $src, 0, 0, 0, 0, $w, $h); /* reduce to palette */ imagetruecolortopalette($tmp, true, 256); if ($hasAlpha) { $idxTrans = imagecolorclosestalpha($tmp, 0, 0, 0, 127); imagecolortransparent($tmp, $idxTrans); } ob_start(); imagegif($tmp); $gifData = ob_get_clean(); imagedestroy($src); imagedestroy($tmp); log_debug('✅ GIF ready (' . strlen($gifData) . ' bytes)'); $base = $inputName ? pathinfo($inputName, PATHINFO_FILENAME) : pathinfo($path, PATHINFO_FILENAME); $finalName = $base . '.gif'; $showPreview = true; } } /* saving */ if ($gifData) { $dir = __DIR__ . '/z_files/emojis/'; if (!is_dir($dir)) mkdir($dir, 0755, true); $dest = $dir . $finalName; $fileExists = file_exists($dest); if (isset($_POST['save'])) { if ($fileExists && !isset($_POST['overwrite'])) { log_debug('⚠️ File exists—confirm overwrite.'); } else { file_put_contents($dest, $gifData); log_debug('💾 Saved to /z_files/emojis/' . $finalName); } } } } } } ?> Image→GIF (transparent)

URL → Transparent GIF




Debug

Preview

gif