use App\Helpers\ImageHelper;
use Intervention\Image\ImageManagerStatic as Image;

public function upload_image($image = NULL)
{
    if ($image) {
        $input = $this->validate([
            'image' => 'uploaded[image]|max_size[image,1024]|ext_in[image,jpg,jpeg,png]',
        ]);
        
        if (!$input) {
            return false;
        } else {
            if ($file = $image) {
                if ($file->isValid() && !$file->hasMoved()) {
                    // Compress and save the image
                    $compressedImage = Image::make($file->getPathname())
                        ->encode('jpg', 80) // Adjust quality as needed
                        ->save('../public/uploads/compressed_' . $file->getName());

                    // Move the original image to uploads directory
                    $file->move('../public/uploads', $file->getName());

                    // Return paths to both original and compressed images
                    return [
                        'original' => '/uploads/' . $file->getName(),
                        'compressed' => '/uploads/compressed_' . $file->getName(),
                    ];
                }
            }
        }
    } else {
        return false;
    }
}
