What is PGM?
PGM is the greyscale member of the Netpbm family: a three-line header, then one brightness value per pixel with no compression. It is what image-processing courses, OCR pipelines and computer-vision tools pass around when they want a format with no decoder in the way.
What is JPG?
JPEG is the format photographs live in. Its compression is lossy - it discards detail the eye is bad at noticing, and discards a little more every time the file is re-saved - which buys enormous size savings on photographic images and makes a mess of screenshots, logos and text. It has no transparency.