From f3f0b3d1f47fc2a6535ad3645cd5001cc31dc183 Mon Sep 17 00:00:00 2001 From: Devdatt Bhatt Date: Thu, 21 May 2026 14:09:36 +0000 Subject: [PATCH] image --- encoder/header.php | 1 + encoder/image.php | 185 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 encoder/image.php diff --git a/encoder/header.php b/encoder/header.php index 7b014f7..1023f2d 100755 --- a/encoder/header.php +++ b/encoder/header.php @@ -1305,6 +1305,7 @@ include 'static.php'; Contact Us Premium Domain SSL + Image diff --git a/encoder/image.php b/encoder/image.php new file mode 100644 index 0000000..66eb579 --- /dev/null +++ b/encoder/image.php @@ -0,0 +1,185 @@ + '/var/www/html/app_ad.png', + 'app_logo' => '/var/www/html/app_logo.png' + ]; + $secondary_dir = '/var/www/encoder/'; + + $errors = []; + + // Handle File Deletions + $to_delete = $_POST['remove_files'] ?? []; + foreach ($to_delete as $file_key => $should_delete) { + if ($should_delete === '1' && isset($upload_paths[$file_key])) { + $path = $upload_paths[$file_key]; + if (file_exists($path)) { + unlink($path); + // Also remove from encoder directory + $secondary_path = $secondary_dir . basename($path); + if (file_exists($secondary_path)) { + unlink($secondary_path); + } + } + } + } + + foreach ($upload_paths as $input_name => $destination) { + if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) { + $tmp_path = $_FILES[$input_name]['tmp_name']; + + // 1. Verify it is actually a PNG using GD/getimagesize + $image_info = @getimagesize($tmp_path); + if (!$image_info || $image_info[2] !== IMAGETYPE_PNG) { + $errors[] = "File for $input_name must be a valid PNG image."; + continue; + } + + $target_width = ($input_name === 'app_logo') ? 128 : 256; + $target_height = ($input_name === 'app_logo') ? 128 : 256; + + // 3. Load the source image + $src_img = @imagecreatefrompng($tmp_path); + if (!$src_img) { + $errors[] = "Failed to process $input_name (Invalid PNG data)."; + continue; + } + + // 4. Create a blank truecolor canvas + $dst_img = imagecreatetruecolor($target_width, $target_height); + + // 5. Preserve transparency for PNG + imagealphablending($dst_img, false); + imagesavealpha($dst_img, true); + $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); + imagefill($dst_img, 0, 0, $transparent); + + // 6. Resize (Resample) + imagecopyresampled( + $dst_img, + $src_img, + 0, + 0, + 0, + 0, + $target_width, + $target_height, + imagesx($src_img), + imagesy($src_img) + ); + + // 7. Save to primary destination with compression (level 7) + if (imagepng($dst_img, $destination, 7)) { + $filename = basename($destination); + $secondary_destination = $secondary_dir . $filename; + + if (!copy($destination, $secondary_destination)) { + $errors[] = "Failed to create secondary copy for $input_name."; + } + } else { + $errors[] = "Failed to save processed $input_name."; + } + + imagedestroy($src_img); + imagedestroy($dst_img); + } + } + + // Save if no errors occurred + if (empty($errors)) { + header("Location: " . $_SERVER['PHP_SELF']); + exit; + } else { + $error_message = implode("
", $errors); + } +} + +include 'header.php'; +?> + + + +
+
+ + + +
+

Image Assets Management

+ + +
+ +
+ + + +
+

Upload Ad (PNG)

+
+ + +
New file selected
+ +
+ + +
+ +
+
+ + +
+

Upload Logo (PNG)

+
+ + +
New file selected
+ +
+ + +
+ +
+
+
+ +
+ +
+
+
+ + \ No newline at end of file