T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/private_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/compress_existing_images.php
<?php
/**
 * Compress Existing Images Script
 * 
 * This script compresses existing uploaded images to reduce file sizes.
 * Run this from command line or via browser (with proper authentication).
 * 
 * Usage: php compress_existing_images.php [--dry-run] [--limit=N]
 */

require_once __DIR__ . '/utils/image_compression.php';

// Configuration
$dry_run = in_array('--dry-run', $argv ?? []);
$limit = null;
foreach ($argv ?? [] as $arg) {
    if (preg_match('/--limit=(\d+)/', $arg, $matches)) {
        $limit = (int)$matches[1];
    }
}

$directories = [
    'uploads/track_covers/' => ['function' => 'compressTrackCover', 'name' => 'Track Covers'],
    'uploads/profile_images/' => ['function' => 'compressProfileImage', 'name' => 'Profile Images'],
    'uploads/cover_images/' => ['function' => 'compressImage', 'name' => 'Cover Images', 'options' => [
        'max_width' => 1920,
        'max_height' => 1080,
        'quality' => 85,
        'convert_png_to_jpeg' => true,
        'max_file_size' => 500 * 1024,
    ]],
];

$total_processed = 0;
$total_saved = 0;
$total_errors = 0;
$results = [];

echo "=== Image Compression Script ===\n";
echo "Mode: " . ($dry_run ? "DRY RUN (no files will be modified)" : "LIVE (files will be compressed)") . "\n";
if ($limit) {
    echo "Limit: Processing maximum $limit files per directory\n";
}
echo "\n";

foreach ($directories as $dir => $config) {
    $full_path = __DIR__ . '/' . $dir;
    
    if (!is_dir($full_path)) {
        echo "⚠️  Directory not found: $dir\n";
        continue;
    }
    
    echo "📁 Processing {$config['name']} in $dir\n";
    
    $files = glob($full_path . '*');
    $files = array_filter($files, 'is_file');
    
    if (empty($files)) {
        echo "   No files found.\n\n";
        continue;
    }
    
    $processed = 0;
    $saved_bytes = 0;
    $errors = 0;
    
    foreach ($files as $filepath) {
        if ($limit && $processed >= $limit) {
            break;
        }
        
        $filename = basename($filepath);
        $original_size = filesize($filepath);
        
        // Skip if already small
        if ($original_size < 50 * 1024) { // Less than 50KB
            continue;
        }
        
        echo "   Processing: $filename (" . formatBytes($original_size) . ")... ";
        
        if ($dry_run) {
            // In dry run, just estimate
            $image_info = @getimagesize($filepath);
            if ($image_info) {
                $estimated_savings = (int)($original_size * 0.5); // Estimate 50% reduction
                echo "DRY RUN - Estimated savings: " . formatBytes($estimated_savings) . "\n";
                $saved_bytes += $estimated_savings;
            } else {
                echo "SKIP - Not a valid image\n";
                $errors++;
            }
        } else {
            // Actually compress
            if ($config['function'] === 'compressImage' && isset($config['options'])) {
                $result = compressImage($filepath, $config['options']);
            } elseif ($config['function'] === 'compressTrackCover') {
                $result = compressTrackCover($filepath);
            } elseif ($config['function'] === 'compressProfileImage') {
                $result = compressProfileImage($filepath);
            } else {
                $result = compressImage($filepath);
            }
            
            if ($result['success']) {
                if (!empty($result['skipped'])) {
                    echo "SKIP - " . ($result['message'] ?? 'Already optimized') . "\n";
                } else {
                    $saved = $result['saved_bytes'];
                    $new_size = $result['new_size'];
                    $percent = $original_size > 0 ? round(($saved / $original_size) * 100, 1) : 0;
                    echo "✓ Compressed to " . formatBytes($new_size) . " (saved " . formatBytes($saved) . ", {$percent}%)\n";
                    $saved_bytes += $saved;
                }
            } else {
                echo "✗ Error: " . ($result['error'] ?? 'Unknown error') . "\n";
                $errors++;
            }
        }
        
        $processed++;
    }
    
    echo "   Summary: Processed $processed files";
    if (!$dry_run) {
        echo ", Saved " . formatBytes($saved_bytes);
    }
    if ($errors > 0) {
        echo ", $errors errors";
    }
    echo "\n\n";
    
    $total_processed += $processed;
    $total_saved += $saved_bytes;
    $total_errors += $errors;
    
    $results[$config['name']] = [
        'processed' => $processed,
        'saved' => $saved_bytes,
        'errors' => $errors,
    ];
}

echo "=== Final Summary ===\n";
echo "Total files processed: $total_processed\n";
if (!$dry_run) {
    echo "Total space saved: " . formatBytes($total_saved) . "\n";
}
if ($total_errors > 0) {
    echo "Total errors: $total_errors\n";
}
echo "\n";

if ($dry_run) {
    echo "⚠️  This was a DRY RUN. No files were modified.\n";
    echo "Run without --dry-run to actually compress images.\n";
}


CasperSecurity Mini