From db8f87a51a4de5fd875ce266066ec99292af7a0c Mon Sep 17 00:00:00 2001 From: Bendang Date: Fri, 22 Jan 2021 17:25:04 +0530 Subject: [PATCH] Update README.md --- README.md | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7decdf4..0af13e4 100644 --- a/README.md +++ b/README.md @@ -84,20 +84,35 @@ Also you can send the file as a FormData (multipart/form-data): ``` ### Usage as a library +Examples: +1. In `app.py` -In `app.py` + ```python + import sys + from rembg.bg import remove -```python -import sys -from rembg.bg import remove + sys.stdout.buffer.write(remove(sys.stdin.buffer.read())) + ``` -sys.stdout.buffer.write(remove(sys.stdin.buffer.read())) -``` + Then run + ``` + cat input.png | python app.py > out.png + ``` + +2. ```python + from rembg.bg import remove + import numpy as np + import io + from PIL import Image -Then run -``` -cat input.png | python app.py > out.png -``` + input_path = 'input.png' + output_path = 'out.png' + + f = np.fromfile(input_path) + result = remove(f) + img = Image.open(io.BytesIO(result)).convert("RGBA") + img.save(output_path) + ``` ### Usage as a docker