Skip to content

🔀 Convert small PNG images to SVG Tiny 1.2

License

Notifications You must be signed in to change notification settings

chrishayles/png2svg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

png2svg GoDoc Go Report Card

Go module and command line utility for converting small PNG files to SVG Tiny 1.2.

Features and limitations

  • Draws rectangles for each region in the PNG image that can be covered by a rectangle.
  • The remaining pixels are drawn with a rectangle for each pixel.
  • This is not an efficient representation of PNG images!
  • The conversion may be useful if you have a small PNG image or icons at sizes around 16x16, and wish to scale it up and print it out without artifacts.
  • The utility is fast for small images, but larger images will take an unreasonable amount of time to convert, creating SVG files many megabytes in size.
  • The resulting SVG images can be opened directly in a browser like Firefox or Chromium.
  • Written in pure Go, with no runtime dependencies on any external library or utility.
  • Handles transparent PNG images by not drawing SVG elements for the transparent regions.
  • For creating SVG images that draws a rectangle for each and every pixel, use the -p flag.

Image Comparison

302x240 PNG image 302x240 SVG image (4096 colors)
171 KB 2.98 MB
png png

The rainforest image is from Wikipedia.

64x64 PNG image 64x64 SVG image (one rectangle per pixel) 64x64 SVG image (optimized) 64x64 SVG image (4096 colors)
2.22 KB 231 KB 71.2 KB 66.7 KB
png png png png

The Glenda bunny is from 9p.io.

Q&A

  • Q: Why 4096 colors?
  • A: Because representing colors on the short form #000 (as opposed to #000000) makes it possible to express 4096 unique colors.

Installation

Development version:

go get -u github.com/xyproto/png2svg/cmd/png2svg

Example usage

Generate an SVG image with one rectangle per pixel:

png2svg -p -o output.svg input.png

Generate an SVG image with as few rectangles as possible (optimized):

png2svg -o output.svg input.png

Generate an SVG image with as few rectangles as possible (4096 colors):

png2svg -q -o output.svg input.png

Like above, but with verbose/progress output:

png2svg -v -q -o output.svg input.png

General information

About

🔀 Convert small PNG images to SVG Tiny 1.2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%