-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da5d102
commit c7a10b3
Showing
9 changed files
with
129 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = '0.2.5' | ||
version = '0.3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import base64 | ||
import datetime | ||
from io import BytesIO | ||
import os | ||
import numpy as np | ||
from PIL import Image | ||
import uuid | ||
|
||
output_dir = os.path.abspath(os.path.join( | ||
os.path.dirname(__file__), '..', 'outputs', 'files')) | ||
os.makedirs(output_dir, exist_ok=True) | ||
|
||
static_serve_base_url = 'http://127.0.0.1:8888/files/' | ||
|
||
|
||
def save_output_file(img: np.ndarray) -> str: | ||
current_time = datetime.datetime.now() | ||
date_string = current_time.strftime("%Y-%m-%d") | ||
|
||
filename = os.path.join(date_string, str(uuid.uuid4()) + '.png') | ||
file_path = os.path.join(output_dir, filename) | ||
|
||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
Image.fromarray(img).save(file_path) | ||
return filename | ||
|
||
|
||
def output_file_to_base64img(filename: str) -> str: | ||
file_path = os.path.join(output_dir, filename) | ||
if not os.path.exists(file_path) or not os.path.isfile(file_path): | ||
return None | ||
|
||
img = Image.open(file_path) | ||
output_buffer = BytesIO() | ||
img.save(output_buffer, format='PNG') | ||
byte_data = output_buffer.getvalue() | ||
base64_str = base64.b64encode(byte_data) | ||
return base64_str | ||
|
||
|
||
def output_file_to_bytesimg(filename: str) -> bytes: | ||
file_path = os.path.join(output_dir, filename) | ||
if not os.path.exists(file_path) or not os.path.isfile(file_path): | ||
return None | ||
|
||
img = Image.open(file_path) | ||
output_buffer = BytesIO() | ||
img.save(output_buffer, format='PNG') | ||
byte_data = output_buffer.getvalue() | ||
return byte_data | ||
|
||
|
||
def get_file_serve_url(filename: str) -> str: | ||
return static_serve_base_url + filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.