2

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.

10
  • 1
    I get the kernel panic with 30 GB of free storage still left on my machine. – Leon Shams Mar 2 at 7:22
  • 1
    Sorry I didn't word that well. I start off with about 71 GB of free storage. I then check how much storage was left as it was processing. It trickled down to 30 GB by the time I got the kernel panic. That means that it had only used up 40 GB. Shouldn't it have used up all 71 GB of storage on my computer before restarting? – Leon Shams Mar 2 at 7:30
  • 1
    It depends on what's happening in the background and how much space ImageMagick tries to allocate at once. It shouldn't kernel panic though (not having enough disk space is still an appliation issue if 30 GB are free) so there might be several problems in parallel here. Is the ppm something you can share (in a zipped version)? – nohillside Mar 2 at 7:39
  • 1
    If the netpbm solution mentioned below doesn't work, can you put the ZIP into a publicly accessible place and share the link? I have more than enough diskspace, could verify the disk space theory. – nohillside Mar 2 at 8:19
  • 2
    Just an FYI.. I used GIMP to convert your file without any issue and have uploaded if you'd like it mandelbrot.png.zip and will be available until Wed Mar 03 2021. BTW I have over 500 GB free space. – user3439894 Mar 2 at 18:11
4

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .