diff --git a/readme.md b/readme.md
index 52045d7..0c0699c 100644
--- a/readme.md
+++ b/readme.md
@@ -48,6 +48,7 @@ Data should be sent form-encoded.
|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|----------|
| `image` | Image file to display. Any image type supported by the Python PIL library should work. | N/A | Yes |
| `mode` | Display mode, corresponding to the `display_XXX` method on the `epd` object.
`FAST` - uses `display_Fast` for a complete screen refresh.
`PARTIAL` - uses `display_Partial` for incremental updates (which may cause ghosting). | `FAST` | No |
+| `dither` | Whether to enable ditering when converting image to mono chromatic. `true` or `1` to enable. | `true` | No |
| `resize` | `FIT` Resize keeping aspect ratio, without cropping
`CROP` Resize keeping aspect ratio, with cropping
`STRETCH` fill display, ignoring aspect ratio
`NONE` Display without any scaling, pixels drawn 1:1. | `FIT` | No |
| `rotate` | Number of degrees to rotate counter-clockwise, supports increments of 90 degrees. | 0 | No |
| `background` | Background colour to use if the image doesn't fill the display. Either `WHITE` or `BLACK`. | `WHITE` | No |
diff --git a/src/img_utils.py b/src/img_utils.py
index cbaa659..21188d5 100644
--- a/src/img_utils.py
+++ b/src/img_utils.py
@@ -1,10 +1,10 @@
from typing import Tuple
from PIL import Image
-from models import Resolution, Rotation, Resize, BackgroundColour, Mode
+from models import Resolution, Rotation, Resize, BackgroundColour
-def resize_img(img: Image, mode: Mode, rotation: Rotation, resize: Resize, background: BackgroundColour,
+def resize_img(img: Image, dither: bool, rotation: Rotation, resize: Resize, background: BackgroundColour,
display_res: Resolution) -> Image:
# Rotate
out_img = img.rotate(angle=rotation, expand=True)
@@ -21,6 +21,9 @@ def resize_img(img: Image, mode: Mode, rotation: Rotation, resize: Resize, backg
scaled_image = out_img.resize(scaled_resolution)
+ dither_setting = Image.Dither.FLOYDSTEINBERG if dither else Image.Dither.NONE
+ scaled_image = scaled_image.convert('1', dither=dither_setting)
+
# Add scaled image to full size canvas
bg_colour = 255 if background == BackgroundColour.WHITE else 0
x = int((display_res.width - scaled_image.width) / 2)
diff --git a/src/server.py b/src/server.py
index e2f779b..5b3d192 100644
--- a/src/server.py
+++ b/src/server.py
@@ -64,7 +64,9 @@ def show_image() -> tuple[Response, int]:
except ValueError:
return jsonify(message=f'"mode" invalid, must be one of {", ".join([x for x in Mode])}'), 422
- image_to_display = resize_img(image, mode, rotate, resize, background, DISPLAY_RESOLUTION)
+ dither = request.form.get('dither', 'true') in ['true', '1']
+
+ image_to_display = resize_img(image, dither, rotate, resize, background, DISPLAY_RESOLUTION)
try:
update_image = image_changed(Image.open(IMG_PATH), image_to_display)