-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add reduce stages, noise source
- Loading branch information
Showing
10 changed files
with
229 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from logging import getLogger | ||
from PIL import Image | ||
|
||
|
||
from ..params import ( | ||
ImageParams, | ||
StageParams, | ||
|
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,30 @@ | ||
from logging import getLogger | ||
from PIL import Image | ||
|
||
from ..params import ( | ||
ImageParams, | ||
Size, | ||
StageParams, | ||
) | ||
from ..utils import ( | ||
ServerContext, | ||
) | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def reduce_crop( | ||
ctx: ServerContext, | ||
_stage: StageParams, | ||
_params: ImageParams, | ||
source_image: Image.Image, | ||
*, | ||
origin: Size, | ||
size: Size, | ||
**kwargs, | ||
) -> Image.Image: | ||
image = source_image.crop( | ||
(origin.width, origin.height, size.width, size.height)) | ||
logger.info('created thumbnail with dimensions: %sx%s', | ||
image.width, image.height) | ||
return image |
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,28 @@ | ||
from logging import getLogger | ||
from PIL import Image | ||
|
||
from ..params import ( | ||
ImageParams, | ||
Size, | ||
StageParams, | ||
) | ||
from ..utils import ( | ||
ServerContext, | ||
) | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def reduce_thumbnail( | ||
ctx: ServerContext, | ||
_stage: StageParams, | ||
_params: ImageParams, | ||
source_image: Image.Image, | ||
*, | ||
size: Size, | ||
**kwargs, | ||
) -> Image.Image: | ||
image = source_image.thumbnail((size.width, size.height)) | ||
logger.info('created thumbnail with dimensions: %sx%s', | ||
image.width, image.height) | ||
return image |
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,38 @@ | ||
from logging import getLogger | ||
from PIL import Image | ||
from typing import Callable | ||
|
||
from ..params import ( | ||
ImageParams, | ||
Size, | ||
StageParams, | ||
) | ||
from ..utils import ( | ||
ServerContext, | ||
) | ||
|
||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
def source_noise( | ||
ctx: ServerContext, | ||
stage: StageParams, | ||
params: ImageParams, | ||
source_image: Image.Image, | ||
*, | ||
size: Size, | ||
noise_source: Callable, | ||
**kwargs, | ||
) -> Image.Image: | ||
prompt = prompt or params.prompt | ||
logger.info('generating image from noise source') | ||
|
||
if source_image is not None: | ||
logger.warn( | ||
'a source image was passed to a noise stage, but will be discarded') | ||
|
||
output = noise_source(source_image, (size.width, size.height), (0, 0)) | ||
|
||
logger.info('final output image size: %sx%s', output.width, output.height) | ||
return output |
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.