    if (auto texture = snapshot.texture()) {
        // Use gdk_texture_save_to_png_bytes if available in GTK 4.4.1
        GRefPtr<GBytes> pngBytes = adoptGRef(gdk_texture_save_to_png_bytes(texture));
        if (!pngBytes) {
            g_warning("Failed to save texture to PNG bytes.");
            return std::nullopt;
        }

        size_t pngSize;
        auto* pngData = static_cast<const uint8_t*>(g_bytes_get_data(pngBytes.get(), &pngSize));
        if (!pngData || pngSize == 0) {
            g_warning("PNG data is empty.");
            return std::nullopt;
        }

        return base64EncodeToString(std::span<const uint8_t>(pngData, pngSize));
    } else {
        g_warning("Snapshot texture is null in GTK4.");
        return std::nullopt;
    }
