Encode images to the X PixMap (XPM3) image format.
The resulting images are smaller than the ones from GIMP, since the question mark character is also used, while at the same time avoiding double question marks, which could result in a trigraph (like ??=
, which has special meaning in C).
Note that the number of colors may be reduced as part of the conversion.
The png2xpm
utility is included.
Converting from a PNG to an XPM file:
// Open the PNG file
f, err := os.Open(inputFilename)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
m, err := png.Decode(f)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
f.Close()
// Create a new XPM encoder
enc := xpm.NewEncoder(imageName)
// Prepare to output the XPM data to either stdout or to file
if outputFilename == "-" {
f = os.Stdout
} else {
f, err = os.Create(outputFilename)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
defer f.Close()
}
// Generate and output the XPM data
err = enc.Encode(f, m)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
- Version: 1.3.0
- License: BSD-3
- Author: Alexander F. Rødseth <[email protected]>