bgremove_flutter 0.0.1 copy "bgremove_flutter: ^0.0.1" to clipboard
bgremove_flutter: ^0.0.1 copied to clipboard

AI-powered background removal for Flutter apps using rembg-webgpu. Fast, client-side image processing with WebGPU acceleration.

RemBG Flutter Plugin #

A Flutter plugin that brings powerful AI-powered background removal to your mobile apps using the rembg-webgpu library. Remove backgrounds from images with WebGPU acceleration for lightning-fast processing.

Features #

  • 🚀 Fast Processing: Uses WebGPU when available, falls back to WASM
  • 📱 Cross-Platform: Works on Android and iOS
  • 🎯 High Quality: Based on rembg.com's production-grade model
  • 📊 Progress Tracking: Real-time progress callbacks
  • 💾 Flexible Output: Support for PNG and WebP formats
  • 🔧 Easy Integration: Simple API with just a few lines of code

Installation #

Add this to your pubspec.yaml:

dependencies:
  rembg_flutter: ^1.0.0
  image_picker: ^1.0.7  # For image selection in examples

Android Setup #

Add internet permission to android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />

iOS Setup #

Add photo library usage description to ios/Runner/Info.plist:

<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photos to remove backgrounds</string>

Quick Start #

import 'package:rembg_flutter/rembg_flutter.dart';

// Initialize the plugin (call once at app start)
await RembgFlutter.initialize();

// Remove background from image
final result = await RembgFlutter.removeBackground(
  imageData: yourImageBytes,
  outputFormat: 'png',
);

// Use the result
File('output.png').writeAsBytesSync(result.imageData);

Usage Examples #

Basic Usage #

import 'dart:io';
import 'package:rembg_flutter/rembg_flutter.dart';

Future<void> removeBackground() async {
  // Initialize
  await RembgFlutter.initialize();
  
  // Load image
  final imageBytes = File('input.jpg').readAsBytesSync();
  
  // Process
  final result = await RembgFlutter.removeBackground(
    imageData: imageBytes,
    outputFormat: 'png',
  );
  
  // Save
  File('output.png').writeAsBytesSync(result.imageData);
}

With Progress Tracking #

final result = await RembgFlutter.removeBackground(
  imageData: imageBytes,
  onProgress: (phase, progress) {
    print('$phase: ${progress.toStringAsFixed(1)}%');
    // Update your UI with progress
  },
);

Check Device Capabilities #

final caps = await RembgFlutter.getCapabilities();
print('Backend: ${caps.device}'); // 'webgpu' or 'wasm'
print('Precision: ${caps.dtype}'); // 'fp16', 'fp32', etc.

final isWebGpuAvailable = await RembgFlutter.isWebGpuSupported();
print('WebGPU supported: $isWebGpuAvailable');

Process from File Path #

final result = await RembgFlutter.removeBackgroundFromFile(
  filePath: '/path/to/image.jpg',
  outputFormat: 'webp',
);

API Reference #

RembgFlutter #

initialize()

Initialize the plugin. Must be called before using other methods.

await RembgFlutter.initialize();

removeBackground()

Remove background from image data.

Future<RemBgResult> removeBackground({
  required Uint8List imageData,
  String outputFormat = 'png',
  ProgressCallback? onProgress,
})

Parameters:

  • imageData: Image bytes (JPEG, PNG, WebP supported)
  • outputFormat: Output format ('png' or 'webp')
  • onProgress: Optional callback for progress updates

Returns: RemBgResult with processed image data

removeBackgroundFromFile()

Remove background from image file.

Future<RemBgResult> removeBackgroundFromFile({
  required String filePath,
  String outputFormat = 'png',
  ProgressCallback? onProgress,
})

getCapabilities()

Get device processing capabilities.

Future<RemBgCapabilities> getCapabilities()

Returns: Device and precision information

isWebGpuSupported()

Check if WebGPU is available on the device.

Future<bool> isWebGpuSupported()

Classes #

RemBgResult

class RemBgResult {
  final Uint8List imageData;
  final String format;
}

RemBgCapabilities

class RemBgCapabilities {
  final String device;  // 'webgpu' or 'wasm'
  final String dtype;   // 'fp16', 'fp32', etc.
}

ProgressCallback

typedef ProgressCallback = void Function(String phase, double progress);

Performance Tips #

  1. Resize large images before processing to improve speed
  2. Use WebP format for smaller output file sizes
  3. Cache processed images to avoid reprocessing
  4. Run on background isolate for heavy workloads

Example App #

Check out the complete example app in example/ directory that demonstrates:

  • Image picking from gallery
  • Real-time progress tracking
  • Before/after comparison
  • Saving processed images

Troubleshooting #

Android WebView Issues #

If you encounter WebView issues on Android, ensure:

  • Internet permission is added
  • WebView is updated on the device
  • Hardware acceleration is enabled

iOS Memory Issues #

For large images on iOS:

  • Resize images before processing
  • Process images one at a time
  • Clear cache between operations

Requirements #

  • Flutter SDK: >=3.0.0
  • Dart SDK: >=3.0.0
  • Android: API 21+ (Android 5.0+)
  • iOS: 12.0+

Credits #

This plugin wraps the excellent rembg-webgpu library by Remove-Background.ai.

License #

MIT License - see LICENSE file for details

1
likes
0
points
228
downloads

Publisher

unverified uploader

Weekly Downloads

AI-powered background removal for Flutter apps using rembg-webgpu. Fast, client-side image processing with WebGPU acceleration.

Repository (GitHub)
View/report issues

Topics

#background-removal #image-processing #ai #webgpu #rembg

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on bgremove_flutter

Packages that implement bgremove_flutter