(in_png, out_png)
| 31 | import sys |
| 32 | from PIL import Image |
| 33 | def png(in_png, out_png): |
| 34 | try: |
| 35 | rgba = Image.open(in_png).convert('RGBA') |
| 36 | except: |
| 37 | err = sys.exc_info()[1] |
| 38 | print(f'make_transparent.save({in_png}) error: {err}') |
| 39 | return |
| 40 | z = np.array(rgba.getdata()) |
| 41 | white_pixel = (z[:,0]==255) * (z[:,1]==255) * (z[:,2]==255) |
| 42 | z[white_pixel,3] = 0 # set alpha to zero = transparent |
| 43 | rgba.putdata([tuple(_) for _ in z]) |
| 44 | try: |
| 45 | rgba.save(out_png, 'PNG') |
| 46 | except: |
| 47 | err = sys.exc_info()[1] |
| 48 | print(f'make_transparent.save({in_png}) error: {err}') |
| 49 | return |
nothing calls this directly
no outgoing calls
no test coverage detected