@@ -1503,6 +1503,7 @@ def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
1503
1503
fig .savefig (thumbfile , dpi = dpi )
1504
1504
return fig
1505
1505
1506
+
1506
1507
def flatten_rgba (src , bg = None ):
1507
1508
"""
1508
1509
Flatten an RGBA image *src* with a background color *bg*.
@@ -1517,7 +1518,7 @@ def flatten_rgba(src, bg=None):
1517
1518
1518
1519
bg : Tuple(int,int,int), optional
1519
1520
Background color to merge *src* with. If no bg color is provided
1520
- the color from the rcParam 'savefig.facecolor' will be use .
1521
+ the color from the rcParam 'savefig.facecolor' will be used .
1521
1522
1522
1523
Returns
1523
1524
-------
@@ -1529,18 +1530,18 @@ def flatten_rgba(src, bg=None):
1529
1530
rcParams .get ('savefig.facecolor' , 'white' ))
1530
1531
bg = tuple ([int (x * 255.0 ) for x in bg ])
1531
1532
1532
- # Numpy images have dtype=uint8 which will overflow
1533
+ # Numpy images have dtype=uint8 which will overflow for these calculations
1533
1534
src = src .astype (np .uint16 )
1534
1535
1535
- alpha = src [:,:, 3 ]
1536
- src_rgb = src [:,:, :3 ]
1536
+ alpha = src [:, :, 3 ]
1537
+ src_rgb = src [:, :, :3 ]
1537
1538
w , h , _ = src .shape
1538
1539
1539
1540
dest = np .empty ((w , h , 4 ))
1540
- dest [:,:, 0 ] = (255 - alpha )* bg [0 ] + alpha * src_rgb [:,:, 0 ]
1541
- dest [:,:, 1 ] = (255 - alpha )* bg [1 ] + alpha * src_rgb [:,:, 1 ]
1542
- dest [:,:, 2 ] = (255 - alpha )* bg [2 ] + alpha * src_rgb [:,:, 2 ]
1541
+ dest [:, :, 0 ] = (255 - alpha )* bg [0 ] + alpha * src_rgb [:, :, 0 ]
1542
+ dest [:, :, 1 ] = (255 - alpha )* bg [1 ] + alpha * src_rgb [:, :, 1 ]
1543
+ dest [:, :, 2 ] = (255 - alpha )* bg [2 ] + alpha * src_rgb [:, :, 2 ]
1543
1544
dest = (dest / 255 ).astype (np .uint8 )
1544
- dest [:,:, 3 ] = 255
1545
+ dest [:, :, 3 ] = 255
1545
1546
1546
1547
return dest
0 commit comments