PGM to PNG Converter

Turn a Netpbm graymap into a PNG that every browser shows.

or drop files here

PG

PGM Format

Portable Graymap

The grayscale member of the Netpbm family of formats. Each pixel is a gray value, stored as plain text or in a binary form.

  • grayscale only
  • 8-bit or 16-bit samples
  • plain text or binary encoding
  • part of Netpbm
PN

PNG Format

Portable Network Graphics

A lossless raster image format developed in the mid-1990s as a patent-free replacement for GIF and standardized as ISO/IEC 15948 and a W3C Recommendation.

  • lossless compression
  • alpha transparency
  • 8-bit and 16-bit channels
  • supported by every browser

How to convert PGM to PNG

Follow these steps to convert PGM to PNG online.

    1

    Choose your PGM file, or several at once.

    2

    Wait while the converter turns each file into PNG.

    3

    Download each new PNG file. Your original file isn't changed.

What to know before converting PGM to PNG

  • Plain (P2) and raw (P5) graymaps are both accepted.
  • A PGM deeper than eight bits a sample comes out with eight.
  • A PGM that holds an opacity mask becomes a gray picture, not transparency.
  • Each file you choose becomes its own PNG.

About PGM files

What is a PGM file?

PGM stands for Portable Gray Map. It is the grayscale member of the Netpbm family and stores one gray value for each pixel. A raw PGM begins with P5 and keeps its samples in binary form. A plain PGM begins with P2 and writes each sample as decimal text. When the Maxval in the header is above 255, every raw sample takes two bytes.

Netpbm also uses PGM for opacity masks, with a different reading of the sample values. The conventional media type is image/x-portable-graymap, which IANA has not registered. People meet PGM in image-processing experiments and in grayscale image interchange.

Programs that open PGM files

Windows, Mac and Linux

  • ImageMagick: reads and writes the PGM member of the Netpbm family.
  • Netpbm: provides programs and libnetpbm for processing graymaps.

PGM and PNG compared

  • Content: a PGM holds gray samples and nothing else. A PNG can hold gray, color and an alpha channel.
  • Encoding: PGM is either plain text or binary. PNG compresses its data without loss.
  • Depth: a raw PGM uses one byte per sample up to a Maxval of 255 and two bytes above it. PNG allows 8-bit and 16-bit channels.
  • Reach: every browser supports PNG, while PGM belongs to image tools.

Here a PGM goes through ImageMagick in your browser and comes out as a PNG. The step adds no filter, and it writes eight bits per sample.

Other ways to convert PGM to PNG

  • Netpbm: run pnmtopng measurement.pgm > measurement.png. The program maps the file's maximum value to a PNG depth.
  • ImageMagick: run magick measurement.pgm review.png.
  • GIMP: use File > Export As, add .png to the file name and confirm with Export. GIMP's PNM reader loads plain and raw files, and the export dialog that follows offers PNG options.

Problems with PGM files

  • A program rejects the file: older readers may refuse samples deeper than eight bits. The pamdepth program from Netpbm can reduce the Maxval.
  • Only the first image shows: some readers stop after one image, although a raw PGM may hold a sequence.
  • The grays look wrong: linear-light and sRGB variants can display differently from the BT.709 reading the specification describes.

Frequently Asked Questions

Everything you need to know about our converter

Why won't my PGM open in a browser or photo app?

Does the page read both P2 and P5 files?

What happens to a 16-bit PGM?

Do my gray values change?

Is a PGM mask the same as a picture?

Does the file get uploaded?

How big can the image be?

Can I convert several PGM files at once?