How to convert file format of massive image
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 &gt; 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.