@@ -138,11 +138,15 @@ def get_rendered_image(self):
138138
139139
140140class ImageEffect (AbstractPathEffect , ImageEffectBase ):
141- def __init__ (self , image_effect , clip_path_getter = None ):
141+ def __init__ (self , image_effect , clip_path_getter = None ,
142+ invisible_if_nill_clip_path = True ):
142143 """
143144
144145 clip_path_getter: set the clip_path of the resulting image. Need to be a callable
145146 or an object with get_clip_path method, which returns a path and a transform.
147+
148+ invisible_if_nill_clip_path: if clip_path_getter is used and if it retune a
149+ nil path of length 0, do not draw the image. Default is True.
146150 """
147151 if clip_path_getter is None or hasattr (clip_path_getter , "get_clip_path" ) or callable (clip_path_getter ):
148152 self ._clip_path_getter = clip_path_getter
@@ -153,6 +157,7 @@ def __init__(self, image_effect, clip_path_getter=None):
153157
154158 self ._image_effect = image_effect
155159 self ._path_effect = None
160+ self ._invisible_if_nill_clip_path = invisible_if_nill_clip_path
156161
157162 def __ror__ (self , other : AbstractPathEffect ):
158163 e = ImageEffect (self ._image_effect )
@@ -190,6 +195,10 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
190195 else :
191196 raise ValueError ("clip_path_getter need to be a callable or an object with get_clip_path method." )
192197
198+ if self ._invisible_if_nill_clip_path and len (clip_path ) == 0 :
199+ self .clear ()
200+ return
201+
193202 pp = TransformedPath (clip_path , affine )
194203
195204 gc .set_clip_path (pp )
0 commit comments