A command-line utility for converting images to Netpbm.
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Command format: convert.py <magic_number> <input_path>
Usage examples:
python convert.py P1 ./example_data/images/cat.jpg # creates ./example_data/images/cat.pbm (black & white)
python convert.py P2 ./example_data/images/dog.jpg # creates ./example_data/images/dog.pgm (grayscale)
python convert.py P3 ./example_data/images/capibara.jpg # creates ./example_data/images/capibara.ppm (full RGB)
Type | Magic number | Extension | Colors |
---|---|---|---|
Portable BitMap | P1 (ASCII) |
.pbm |
0-1 (black & white) |
Portable GrayMap | P2 (ASCII) |
.pgm |
0-255 (grayscale) |
Portable PixMap | P3 (ASCII) |
.ppm |
0-255 per RGB channel |
- No support for magic numbers
P4
-P6
(raw binary) - No support for multibyte GrayMap
cat.jpg
: JackieLou DL on Pixabaydog.jpg
: Fran • @mallorcadogphotography on Pixabaycapibara.jpg
: Masakazu Kobayashi on Pixabay