Skip to content

Commit

Permalink
Update README.MD
Browse files Browse the repository at this point in the history
  • Loading branch information
pzmudzinski committed Dec 27, 2023
1 parent f76ca09 commit e2f4485
Showing 1 changed file with 70 additions and 6 deletions.
76 changes: 70 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ iOS 16.0 or later / macOS 12 or later.

### Installing via Swift Package Manager (SPM)

You can easily integrate OpenGraphReader into your project using Swift Package Manager:
You can easily integrate `RemoveBg` into your project using Swift Package Manager:

1. Open your Xcode project.
2. Click on "File" > "Swift Packages" > "Add Package Dependency..."
Expand All @@ -35,16 +35,80 @@ You can easily integrate OpenGraphReader into your project using Swift Package M

Import the package and use it to interact with the remove.bg API.

Example:
### Basic

```swift
import RemoveBg

// Configure the API client
let client = RemoveBGClient(apiKey: "your-api-key")

let result = try await client.removeBackground(fromImageData: image.jpegRepresentation(0.8))
let imageResult = UIImage(data: result.imageData)
let client = RemoveBgClient(apiKey: "my-api-key")
let result = try await client.removeBackground(fromImageData: imageData)
let image = UIImage(data: result.imageData)
```

### Configuration

You can configure all available removal options using `ApiOptions`:

```swift
let apiOptions = ApiOptions(size: .preview, bgColor: "#F00")
let result = try await client.removeBackground(fromImageData: loaded, options: apiOptions)
```

### Diferent image inputs

You can also use remote URL or base64 string as image input:

```swift
try await client.removeBackground(fromFileAtUrl: ...)
try await client.removeBackground(fromBase64Image: ...)
```

### Reading result meta

`ApiResult` contains `meta` object containing all information about request made, such as credits charged or foreground position:

```swift
result.meta?.creditsCharged
```

### Full SwiftUI example

```swift
struct ContentView: View {
@State private var avatarItem: PhotosPickerItem?
@State private var image: UIImage?

var body: some View {
VStack {
PhotosPicker("Select image", selection: $avatarItem, matching: .images)

if let image {
Image(uiImage: image)
.resizable()
.scaledToFit()
.frame(width: 300, height: 300)
}
}
.onChange(of: avatarItem) {
Task {
if let loaded = try? await avatarItem?.loadTransferable(type: Data.self) {
do {
let client = RemoveBgClient(apiKey: "my-api-key")

let result = try await client.removeBackground(fromImageData: loaded)

self.image = UIImage(data: result.imageData)
} catch {
print(error)
}
} else {
print("Failed")
}
}
}
}
}
```

## License
Expand Down

0 comments on commit e2f4485

Please sign in to comment.