THERMAL ABSORPTION AS THE CAUSE OF GIGAHERTZ-PEAKED SPECTRA IN PULSARS AND MAGNETARS