Skip to content

Commit

Permalink
V0.6 -- support transparent PNG images by applying white background
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
jnweiger committed Nov 7, 2016
1 parent 01c54ce commit 275867a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion centerline-trace.inx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
https://github.com/fablabnbg/inkscape-centerline-trace
</param>
<!-- Keep in sync with centerline_trace.py line 16 __version__ = ... -->
<param name="about_version" type="description">Version 0.5</param>
<param name="about_version" type="description">Version 0.6</param>

<effect needs-live-preview="false" >
<object-type>path</object-type>
Expand Down
10 changes: 9 additions & 1 deletion centerline-trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
# 2016-05-16 jw, V0.4 -- added replace option. Made filters optional.
# 2016-11-05 jw, V0.5 -- support embedded jpeg (and possibly other file types)
# https://github.com/fablabnbg/inkscape-centerline-trace/issues/8
# 2016-11-06 jw, V0.6 -- support transparent PNG images by applying white background
# https://github.com/fablabnbg/inkscape-centerline-trace/issues/3

__version__ = '0.5' # Keep in sync with centerline-trace.inx ca line 22
__version__ = '0.6' # Keep in sync with centerline-trace.inx ca line 22
__author__ = 'Juergen Weigert <[email protected]>'

import sys, os, re, math, tempfile, subprocess, base64
Expand Down Expand Up @@ -171,6 +173,12 @@ def svg_centerline_trace(self, image_file):

if debug: print >>sys.stderr, "svg_centerline_trace start "+image_file
im = Image.open(image_file)
if 'A' in im.mode:
# this image has alpha. Paste it onto white.
im = im.convert("RGBA")
white = Image.new('RGBA', im.size, (255,255,255,255))
im = Image.alpha_composite(white, im)

im = im.convert(mode='L', dither=None)
if debug: print >>sys.stderr, "seen: " + str([im.format, im.size, im.mode])
scale_limit = math.sqrt(im.size[0] * im.size[1] * 0.000001 / self.megapixel_limit)
Expand Down

0 comments on commit 275867a

Please sign in to comment.