Skip to content

Commit

Permalink
Merge pull request #47 from abertschi/develop
Browse files Browse the repository at this point in the history
introduce fallback_color_fill
  • Loading branch information
abertschi authored Aug 12, 2023
2 parents ad1fcf1 + 8b21d7a commit 88f1750
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ The following keyword arguments are available for advanced configuration.
**PostcardCreator#send_free_card()**:
- `image_export=False`: Export postcard image to current directory (os.getcwd)
- `mock_send=False`: Do not submit order (testing)
- `fallback_color_fill=False`: On False: If image is too small, force upscale to
match postcard aspect ration (background-size: contain), on True: fallback to
color fill mode where image is centered and border is filled with most
dominant color found in image.

### Logging
```python
Expand Down Expand Up @@ -77,6 +81,8 @@ pytest
- [postcardcreator](https://github.com/gido/postcardcreator) - node.js API for the Swiss Post Postcard Creator

## Release notes
### 2.4, 2023-08-12
- add fallback_color_fill parameter in send_free_card()
### v2.3, 2022-09-30
- changes in internals of swissid token authentication due to introduction of anomaly-detection #41

Expand Down
2 changes: 1 addition & 1 deletion postcard_creator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.3'
__version__ = '2.4'
8 changes: 6 additions & 2 deletions postcard_creator/postcard_img_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def rotate_and_scale_image(file, image_target_width=154,
image_quality_factor=20,
image_rotate=True,
image_export=False,
enforce_size=False, # = True, will not make image smaller than given w/h
enforce_size=False, # = True, will not make image smaller than given w/h, for high resolution submissions
fallback_color_fill=False, # = False, will force resize cover even if image is too small.
img_format='PNG',
**kwargs):
with Image.open(file) as image:
Expand All @@ -45,8 +46,11 @@ def rotate_and_scale_image(file, image_target_width=154,
# XXX: swissid endpoint expect specific size for postcard
# if we have an image which is too small, do not upsample but rather center image and fill
# with boundary color which is most dominant color in image
#
# validate=True will throw exception if image is too small
#
try:
cover = resizeimage.resize_cover(image, [width, height])
cover = resizeimage.resize_cover(image, [width, height], validate=fallback_color_fill)
except Exception as e:
logger.warning(e)
logger.warning(f'resizing image from {image.width}x{image.height} to {width}x{height} failed.'
Expand Down

0 comments on commit 88f1750

Please sign in to comment.