@@ -20,7 +20,7 @@ def create_background_rect(img, padding):
2020 rect .close ()
2121 return rect
2222
23- def remove_layering (traced_bitmaps , img ):
23+ def remove_layering (traced_bitmaps , img , has_background ):
2424 """
2525 Performs boolean operations on a list of traced bitmaps
2626 to ensure that they are all disjoint.
@@ -35,6 +35,7 @@ def remove_layering(traced_bitmaps, img):
3535 Parameters:
3636 traced_bitmaps: The list of traced bitmaps (potrace paths).
3737 img: A Pillow image.
38+ has_background: Whether the image has a transparent background
3839
3940 Returns:
4041 The processed list of compound paths.
@@ -43,6 +44,19 @@ def remove_layering(traced_bitmaps, img):
4344 potrace_path_to_compound_path (traced ) for traced in traced_bitmaps
4445 ]
4546
47+ if has_background :
48+ # If there's a transparent background, the boolean trick
49+ # can't be used because the top path (the one who contains all
50+ # the subsequent ones before they are separated) does not cover
51+ # the total area of the image
52+ for x in range (len (compound_paths ) - 1 ):
53+ next = compound_paths [x + 1 ]
54+ try :
55+ compound_paths [x ] = op (compound_paths [x ], next , PathOp .DIFFERENCE )
56+ except :
57+ break
58+ return compound_paths
59+
4660 disjoint_paths = []
4761 for x in range (len (compound_paths ) - 1 ):
4862 # Each base path has bigger padding to reduce
0 commit comments