Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

xyproto/xpm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xpm

Build Status Go Report Card GoDoc License

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.

Example use

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)
}

Reference documentation

General info

About

Encode images in the X PixMap (XPM3) image format

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages