A row of pixels is a function of position. A cosine series rewrites it as an average plus waves of increasing frequency. Keep the big low-frequency waves, round away the tiny high ones, and the picture barely changes while the file shrinks.