Could you add these Nav2 links to your answer, with description of your problems? Only then you can expect some useful answers.
What kind of image do you want to convert? Do you want to convert probability map to ROS OccupancyGrid message?
You can do it by hand with PGM files by threshold of every cell either to 0 or 1, then up/down scaling to fit chosen resolution. It could be done automatically with some graphics library, e.g. Shapely (Python).
You can base your implementation on some ROS packages like this one: https://github.com/awesomebytes/occup... (ROS1), https://github.com/clearpathrobotics/... (ROS1) etc.
You can find even more for sure.