Skip to content

handy function for converting high-res whiteboard sketches to crisp, transparent PNGs

License

Notifications You must be signed in to change notification settings

aaronpolhamus/transparent-png

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

transparent-png

handy function for converting high-res whiteboard sketches to crisp, transparent background PNGs. Thanks for the wicked-awesome Marciana drawing, Monica ;)

Getting running

Super easy:

  • clone this repo
  • cd transparent-png
  • pip install -r requirements.txt
  • To test: python converter.py

Here's the result you should get:

Imgur

Here's a more fully-feature version. This works best on whiteboard sketches where the target colors are very consistent, but the visual effect is cool nonetheless:

python converter.py --in_file ./balloons-over-bagan.jpg --out_file ./balloons.png --targets 182 109 58 121 29 39 103 118 77 --steepness 0.25 --offset 40

Takes you from this...

Imgur

to this:

Imgur

Tuning the conversion

I use a sigmoid function the looks at how dark a pixel is and, based on that, assigns it an alpha transparency. The sigmoid function is nice because it renders a smooth gradient against a transparent background, avoiding the awkward discontinuities that a simple threshold would create. The defaults I picked worked pretty well, but if you'd like to play with them this is the function you'll be adjusting:

Imgur

--offset shifts the curve right and left, and --steepness controls the steepness of the transparency gradient. The larger this number, the closer your approximation to a strict threshold for transparency will be.

About

handy function for converting high-res whiteboard sketches to crisp, transparent PNGs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages