Manatee

How to convert a PGM or PPM image to PNG on a Mac

PBM, PGM and PPM are very simple image formats from the Netpbm family, common in programming courses, research code and image tools. They are often too basic for Preview or Photos to open, so the quick answer is to convert them to PNG, which keeps every pixel exactly and opens everywhere.

What these three formats are

The three extensions describe the same idea at different color depths.

  • PBM is a black and white image, one bit per pixel.
  • PGM is grayscale, with shades from black to white.
  • PPM is full color, with red, green and blue values for each pixel.

The files have no compression. Many begin with a short line of text, such as P3 or P6, followed by the width, height and the pixel values. Some versions are literally readable text, which is why programming exercises and image processing scripts often write them: they are easy to produce with a few lines of code.

That same simplicity explains why they feel obscure. Cameras and phones never make them, so Apple has little reason to build in strong support, and results vary between apps and versions of macOS. When a file will not open, or opens as noise, converting is the dependable route.

Why they are so large

Because nothing is compressed, a PPM is roughly three bytes for every pixel. A photo-sized image can be many megabytes, while the same picture as a PNG is far smaller with no change in appearance. PNG compresses without losing anything, so you gain disk space for free. Why zipping photos and videos barely makes them smaller is about files that are already compressed; a raw bitmap is the opposite case, and compresses well.

Convert with Manatee

Manatee reads PBM, PGM and PPM and writes PNG, JPEG, TIFF and more. It runs entirely on your Mac, with nothing uploaded, and has its own conversion engine built in.

  1. Open Manatee and choose Convert.
  2. Drop your image files into the window, or onto the menu bar icon. A whole folder of them can go in at once.
  3. Choose PNG as the target. It keeps every pixel as it was.
  4. Each converted image is saved next to its original, which is never modified.

If you want a file to post or email, choose JPEG instead; it is smaller but lossy. For an exact copy that opens in any app, stay with PNG. Manatee is free for 24 hours with every feature, then $9 once.

If you have a large set, how to convert a batch of files at once covers the approach.

Convert with Preview if it opens

If Preview does open your file, you can convert it without any extra app.

  1. Open the image in Preview.
  2. Choose File, then Export.
  3. Pick PNG from the Format menu and save.

This only works if Preview recognizes the file. If it shows a blank window or an error, use another route. Also, it handles one file at a time, which is slow for a folder of results.

Convert with Terminal if you have ffmpeg

If ffmpeg is installed, it can read these formats directly:

ffmpeg -i image.ppm image.png

For a numbered sequence, such as frame0001.ppm and onward, a loop turns the lot into PNG files:

for f in *.ppm; do ffmpeg -i "$f" "${f%.ppm}.png"; done

Things that can look wrong

  • A grayscale image that turns out in color. A PGM holds only shades of gray. After conversion it may be saved as a color PNG that contains only gray values, which is normal and looks the same.
  • A very dark or very bright picture. Some files use a maximum value other than 255, so tools that assume 255 may show them wrongly. If the result looks off, try opening the converted PNG in Preview to compare against what your source program displays.
  • A file that will not convert at all. A cut-off write can leave a file shorter than its header says. Preview and most converters will reject it, and a partly drawn image is the best case. Can a corrupted photo be repaired explains what is realistic.

Questions

Is PNG a good replacement for PPM? Yes for storage and sharing. PNG is lossless, so every pixel is preserved, and the file is far smaller. Keep the PPM only if another program in your workflow needs that exact format.

Will transparency be added? No. These formats have no transparency, so the PNG will be fully opaque.

Is my original image touched? No. The converted PNG is a new file beside it, and the PGM or PPM stays as it was.