-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): save image params along with image (#81)
- Loading branch information
Showing
8 changed files
with
102 additions
and
55 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
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 |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
run_gc, | ||
) | ||
|
||
import gc | ||
import numpy as np | ||
|
||
logger = getLogger(__name__) | ||
|
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,50 @@ | ||
from json import dumps | ||
from PIL import Image | ||
from typing import Any, Optional | ||
|
||
from .params import ( | ||
Border, | ||
ImageParams, | ||
Size, | ||
UpscaleParams, | ||
) | ||
from .utils import ( | ||
base_join, | ||
ServerContext, | ||
) | ||
|
||
|
||
def json_params( | ||
output: str, | ||
params: ImageParams, | ||
size: Size, | ||
upscale: Optional[UpscaleParams] = None, | ||
border: Optional[Border] = None, | ||
) -> Any: | ||
return { | ||
'border': border.tojson(), | ||
'output': output, | ||
'params': params.tojson(), | ||
'size': upscale.resize(size.add_border(border)).tojson(), | ||
'upscale': upscale.tojson(), | ||
} | ||
|
||
|
||
def save_image(ctx: ServerContext, output: str, image: Image.Image) -> str: | ||
path = base_join(ctx.output_path, output) | ||
image.save(path) | ||
return path | ||
|
||
|
||
def save_params( | ||
ctx: ServerContext, | ||
output: str, | ||
params: ImageParams, | ||
size: Size, | ||
upscale: Optional[UpscaleParams] = None, | ||
border: Optional[Border] = None, | ||
) -> str: | ||
path = base_join(ctx.output_path, '%s.json' % (output)) | ||
json = json_params(output, params, size, upscale=upscale, border=border) | ||
with open(path, 'w') as f: | ||
f.write(dumps(json)) |
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