Skip to content

Commit

Permalink
Added grayscale image support in put_image_data and exposed image_smo…
Browse files Browse the repository at this point in the history
…othing_enabled attribute (#353)

* Added grayscale image support in put_image_data and exposed image_smoothing_enabled attribute

* Linter

---------

Co-authored-by: AnyaPorter <porter.anya@sbcglobal.net>
  • Loading branch information
martinRenou and AnyaPorter authored Sep 5, 2024
1 parent 47f10f2 commit 5ade708
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ipycanvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ class Canvas(_CanvasBase):
#: This property has no effect on Safari, see https://bugs.webkit.org/show_bug.cgi?id=198416
filter = Unicode("none")

#: (bool) Indicates if scaled images are smoothed. Default to True
image_smoothing_enabled = Bool(True)

_line_dash = List()

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

def __init__(self, *args, **kwargs):
Expand Down
4 changes: 3 additions & 1 deletion ipycanvas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def image_bytes_to_array(im_bytes):

def binary_image(ar, quality=75):
f = BytesIO()
if ar.shape[2] == 3:
if len(ar.shape) == 2:
filetype = "PNG"
elif ar.shape[2] == 3:
filetype = "JPEG"
else:
filetype = "PNG"
Expand Down
3 changes: 2 additions & 1 deletion src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ export class CanvasModel extends DOMWidgetModel {
'shadowOffsetY',
'shadowBlur',
'shadowColor',
'filter'
'filter',
'imageSmoothingEnabled'
];

initialize(attributes: any, options: any) {
Expand Down

0 comments on commit 5ade708

Please sign in to comment.