What is JPG?
JPEG is where photographs live. Its compression is lossy - it throws away detail the eye is bad at noticing, and throws away a bit more every time you re-save - which buys huge size savings on photos and makes a mess of screenshots and text. There's no transparency in it at all.
What is PGM?
Greyscale, uncompressed, with a header you can read in a text editor. PGM is part of the netpbm family, and it exists because sometimes you want pixel values you can do arithmetic on without a decoder in the way. Image processing and computer vision code loves it.