The spec says…
Note. This specification does not fully define the interaction of
::beforeand::afterwith replaced elements (such as IMG in HTML). This will be defined in more detail in a future specification.
I guess this means they don’t work with img elements (for now).
Also see this answer.