How to convert file format of massive image

file conversionfinderpreviewterminal

How can I convert a very large Portable Pixel Map (ppm) file into a png on MacOS?

I have a massive ppm image on my computer. The file is ~70 GB and I need to convert it to a png which would make it ~100 MB. I have cleared up enough space (>70 GB) on my machine to complete the conversion but am having some issues.

What I Have Tried

  1. Open image in preview and export to png

    Preview refuses to show the image and instead just shows a black square. When I try to export it tells me that the exported file will be zero bytes. So… no dice.

  2. Use ImageMagick to convert the file from terminal

    This actually runs and tries to convert the file, but problems arise after about a minute of computation. First, my computer freezes then after a minute or two restarts because of a kernel panic.

Best Answer

netpbm

Netpbm is a package of graphics programs and a programming library.

Try using the open source netpbm tools to perform the conversion. The conversion will likely look like:

 pnmtopng input.ppm > output.png

Where input.ppm is the name of the existing large file and output.png is the name of the desired png formatted file.

The project talks about trying to keep memory use low:

Memory Usage

An important characteristic that varies among graphics software is how much memory it uses, and how. Does it read an entire image into memory, work on it there, then write it out all at once? Does it read one and write one pixel at a time? In Netpbm, it differs from one program to the next, but there are some generalizations we can make.

Most Netpbm programs keep one row of pixels at a time in memory. Such a program reads a row from an input file, processes it, then writes a row to an output file. Some programs execute algorithms that can't work like that, so they keep a small window of rows in memory. Others must keep the entire image in memory. If you think of what job the program does, you can probably guess which one it does.

Installing

You can install netpbm on your Mac using the Homebrew project, see Install Homebrew. Once brew is on your Mac, use the following command to install netpbm:

brew install netpbm

If you need help using the command line or tools mentioned, please ask questions.