https://github.com/jmp/farbfeld
A small Python module for reading and writing farbfeld images (https://tools.suckless.org/farbfeld/). Currently supports reading and writing pixel values to/from farbfeld image files.
https://github.com/jmp/farbfeld
farbfeld image pixels python
Last synced: about 1 year ago
JSON representation
A small Python module for reading and writing farbfeld images (https://tools.suckless.org/farbfeld/). Currently supports reading and writing pixel values to/from farbfeld image files.
- Host: GitHub
- URL: https://github.com/jmp/farbfeld
- Owner: jmp
- License: mit
- Created: 2019-01-23T20:12:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-31T08:08:19.000Z (over 6 years ago)
- Last Synced: 2025-02-23T16:40:34.214Z (about 1 year ago)
- Topics: farbfeld, image, pixels, python
- Language: Python
- Homepage: https://github.com/jmp/farbfeld
- Size: 33.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# farbfeld.py
[](https://travis-ci.org/jmp/farbfeld)
[](https://codecov.io/gh/jmp/farbfeld)
[](https://lgtm.com/projects/g/jmp/farbfeld/context:python)
[](https://badge.fury.io/py/farbfeld)
This is a small Python module for reading and writing pixel data
from farbfeld images (https://tools.suckless.org/farbfeld/).
## Installation
The module is available on PyPI: https://pypi.org/project/farbfeld/
You can install it with `pip`:
pip install farbfeld
## Usage
To read an image, open the desired file and read the pixels
from it using `farbfeld.read`:
```python
import farbfeld
with open('image.ff', 'rb') as f:
data = farbfeld.read(f)
```
Note that since farbfeld stores pixel components as 16-bit
unsigned integers, you may have to normalize them or scale
them to a different range (e.g. 8-bit). For example, using
NumPy and Matplotlib:
```python
import farbfeld
import numpy as np
import matplotlib.pyplot as plt
with open('image.ff', 'rb') as f:
data = farbfeld.read(f)
data_8bit = np.array(data).astype(np.uint8)
plt.imshow(data_8bit, interpolation='nearest')
plt.show()
```
To write a farbfeld image, open the desired file and write the pixels
into it using `farbfeld.write`:
```python
import farbfeld
# An example 2x2 image
data = [
[[1, 2, 3, 4], [5, 6, 7, 8]],
[[9, 10, 11, 12], [13, 14, 15, 16]],
]
with open('image.ff', 'wb') as f:
farbfeld.write(f, data)
```
## Source code
The source code is available on GitHub:
https://github.com/jmp/farbfeld