Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xyproto/xpm
Encode images in the X PixMap (XPM3) image format
https://github.com/xyproto/xpm
encode format go image xpm xpm3
Last synced: about 14 hours ago
JSON representation
Encode images in the X PixMap (XPM3) image format
- Host: GitHub
- URL: https://github.com/xyproto/xpm
- Owner: xyproto
- License: bsd-3-clause
- Created: 2019-06-24T10:09:11.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-24T10:24:39.000Z (almost 2 years ago)
- Last Synced: 2024-12-25T09:22:51.259Z (17 days ago)
- Topics: encode, format, go, image, xpm, xpm3
- Language: Go
- Homepage:
- Size: 2.65 MB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# xpm
![Build Status](https://github.com/xyproto/xpm/workflows/Build/badge.svg) [![Go Report Card](https://goreportcard.com/badge/github.com/xyproto/xpm)](https://goreportcard.com/report/github.com/xyproto/xpm) [![GoDoc](https://godoc.org/github.com/xyproto/xpm?status.svg)](https://godoc.org/github.com/xyproto/xpm) [![License](https://img.shields.io/badge/license-BSD-blue.svg?style=flat)](https://raw.githubusercontent.com/xyproto/xpm/main/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:
```go
// 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
* [The XPM reference](https://www.xfree86.org/current/xpm.pdf)
## General info
* Version: 1.3.0
* License: BSD-3
* Author: Alexander F. Rødseth <[email protected]>