mirror of
https://git.mirrors.martin98.com/https://github.com/danielgatis/rembg
synced 2025-08-18 03:45:57 +08:00
Update README.md
This commit is contained in:
parent
b8e0812497
commit
3558a53d1f
55
README.md
55
README.md
@ -84,35 +84,44 @@ Also you can send the file as a FormData (multipart/form-data):
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Usage as a library
|
### Usage as a library
|
||||||
Examples:
|
|
||||||
1. In `app.py`
|
|
||||||
|
|
||||||
```python
|
#### Example 1: Read from stdin and write to stdout
|
||||||
import sys
|
|
||||||
from rembg.bg import remove
|
|
||||||
|
|
||||||
sys.stdout.buffer.write(remove(sys.stdin.buffer.read()))
|
In `app.py`
|
||||||
```
|
```python
|
||||||
|
import sys
|
||||||
|
from rembg.bg import remove
|
||||||
|
|
||||||
Then run
|
sys.stdout.buffer.write(remove(sys.stdin.buffer.read()))
|
||||||
```
|
```
|
||||||
cat input.png | python app.py > out.png
|
|
||||||
```
|
Then run
|
||||||
|
```
|
||||||
|
cat input.png | python app.py > out.png
|
||||||
|
```
|
||||||
|
|
||||||
2. ```python
|
#### Example 2: Using PIL
|
||||||
from rembg.bg import remove
|
|
||||||
import numpy as np
|
|
||||||
import io
|
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
input_path = 'input.png'
|
In `app.py`
|
||||||
output_path = 'out.png'
|
```python
|
||||||
|
from rembg.bg import remove
|
||||||
|
import numpy as np
|
||||||
|
import io
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
f = np.fromfile(input_path)
|
input_path = 'input.png'
|
||||||
result = remove(f)
|
output_path = 'out.png'
|
||||||
img = Image.open(io.BytesIO(result)).convert("RGBA")
|
|
||||||
img.save(output_path)
|
f = np.fromfile(input_path)
|
||||||
```
|
result = remove(f)
|
||||||
|
img = Image.open(io.BytesIO(result)).convert("RGBA")
|
||||||
|
img.save(output_path)
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run
|
||||||
|
```
|
||||||
|
python app.py
|
||||||
|
```
|
||||||
|
|
||||||
### Usage as a docker
|
### Usage as a docker
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user