It's kinda two separate things, encoding is the practice of how the visual data is stored. A very simple example would be that encoding for talking is written language, for each vowel, we set one character like A. So to encode spoken language to text, we use the 26 characters in the alphabet.
Compression on the other hand is the practice of reducing the storage space required to store said encoding. To continue with the language example, instead of saying "It is", we just write "It's" and have thus saved 1 character. Or instead of writing "Best Regards" we write "BR". This is compression, since it requires less space to write. Compression comes in two forms, lossy or lossless, in lossless compression, all data is stored, just in a smaller size, like in "It is" -> "It's", the meaning is still the same. Lossy on the otherhand removes some information, "BR" isn't definitely "Best Regards", but could also be anything else. So we lost some information there. But since we know what BR in a letter means, we can still read it correctly.
Encoding is always neccessary to store visual data, but compression is not.