Skip to content

Commit 5ade708

Browse files
Added grayscale image support in put_image_data and exposed image_smoothing_enabled attribute (#353)
* Added grayscale image support in put_image_data and exposed image_smoothing_enabled attribute * Linter --------- Co-authored-by: AnyaPorter <[email protected]>
1 parent 47f10f2 commit 5ade708

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

ipycanvas/canvas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ class Canvas(_CanvasBase):
575575
#: This property has no effect on Safari, see https://bugs.webkit.org/show_bug.cgi?id=198416
576576
filter = Unicode("none")
577577

578+
#: (bool) Indicates if scaled images are smoothed. Default to True
579+
image_smoothing_enabled = Bool(True)
580+
578581
_line_dash = List()
579582

580583
#: (float) Specifies where to start a dash array on a line. Default is ``0.``.
@@ -614,6 +617,7 @@ class Canvas(_CanvasBase):
614617
"shadow_blur": 15,
615618
"shadow_color": 16,
616619
"filter": 17,
620+
"image_smoothing_enabled": 18,
617621
}
618622

619623
def __init__(self, *args, **kwargs):

ipycanvas/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def image_bytes_to_array(im_bytes):
2727

2828
def binary_image(ar, quality=75):
2929
f = BytesIO()
30-
if ar.shape[2] == 3:
30+
if len(ar.shape) == 2:
31+
filetype = "PNG"
32+
elif ar.shape[2] == 3:
3133
filetype = "JPEG"
3234
else:
3335
filetype = "PNG"

src/widget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ export class CanvasModel extends DOMWidgetModel {
609609
'shadowOffsetY',
610610
'shadowBlur',
611611
'shadowColor',
612-
'filter'
612+
'filter',
613+
'imageSmoothingEnabled'
613614
];
614615

615616
initialize(attributes: any, options: any) {

0 commit comments

Comments
 (0)