Free PGM test files and sample generator
A Netpbm 8-bit grayscale image. Generate valid .pgm sample files for testing image converters, computer-vision tooling and pipelines.
What is a .pgm file?
PGM: Portable Graymap Image. PGM is the grayscale member of the Netpbm family, one byte per pixel after a text header. It is the usual intermediate format for OCR, thresholding and computer-vision work.
Why generate a test PGM file?
- Test grayscale processing, thresholding or OCR intake.
- Verify single-channel image handling.
- Exercise conversion between grayscale and color formats.
What you can put inside a .pgm file
You get 3 content options for PGM, so the file holds something meaningful rather than random padding: Solid color, Gradient, Checkerboard. For PGM these are alternatives, so choose the one that matches what you need to test.
How a .pgm file is identified
Every .pgm file begins with 50 35, "P5", binary grayscale Netpbm. That is what a validator inspecting content rather than the file name looks for.
How the size lands on the exact byte
Header comment lines absorb the remainder; the height carries the bulk of the size.
Negative testing with broken PGM files
- Invalid. Identifiable, but wrong inside, so it fails during parsing.
- Corrupted. The leading bytes are destroyed, so the
50 35identifying a .pgm is gone. Same length as the valid file. - Incomplete. Truncated part-way, so it is genuinely shorter.
- Empty. Chosen under Content rather than File Condition: valid structure, no data.
Which failure to reach for, and what to assert for each, is covered in how to make a corrupted file for testing. For upload limits and type checks see testing file upload validation.
Sample PGM content
[PGM], P5 binary Netpbm: magic, width/height, maxval, raw gray pixels.
This shows the shape of the file. Your download is generated fresh at the size you choose, so the values will differ.
How to open and verify the file
Open in GIMP or IrfanView; convert with `pgmtopng` or ImageMagick.
Media type image/x-portable-graymap · extension .pgm · category Images
Generate a .pgm file → · questions about sizes, privacy or cost are answered on the site FAQ.
Frequently asked questions about PGM files
What identifies a .pgm file?
A .pgm file begins with the bytes 50 35, "P5", binary grayscale Netpbm. Those bytes are what a content-sniffing validator looks for, and what the Corrupted condition destroys.
How can a .pgm file be an exact number of bytes?
Header comment lines absorb the remainder; the height carries the bulk of the size.
What can go inside the PGM file?
There are 3 content options for .pgm: Solid color, Gradient, Checkerboard. For PGM these are alternatives, so pick the one matching what you need to test.
Can I download several broken PGM files at once?
Yes, select more than one File Condition and you get one ZIP containing a .pgm per condition, each named after its condition.
Can the PGM file use UTF-16 or a byte-order mark?
No, and deliberately. A .pgm file is a container rather than plain text, so rewriting its bytes as UTF-16 would not produce a UTF-16 document. It would produce a broken file. Use a text format such as CSV, JSON or XML for encoding tests.
How do I open or verify the PGM file?
Open in GIMP or IrfanView; convert with pgmtopng or ImageMagick.