We present a lattice calculation of the electromagnetic (EM) effects on the masses of light pseudoscalar mesons. The simulations employ $2+1$ dynamical flavors of asqtad QCD quarks and quenched photons. Lattice spacings vary from $\ensuremath{\approx}0.12\text{ }\text{ }\mathrm{fm}$ to $\ensuremath{\approx}0.045\text{ }\text{ }\mathrm{fm}$. We compute the quantity $\ensuremath{\epsilon}$, which parametrizes the corrections to Dashen's theorem for the ${K}^{+}$--${K}^{0}$ EM mass splitting, as well as ${\ensuremath{\epsilon}}_{{K}^{0}}$, which parametrizes the EM contribution to the mass of the ${K}^{0}$ itself. An extension of the nonperturbative EM renormalization scheme introduced by the BMW group is used in separating EM effects from isospin-violating quark mass effects. We correct for leading finite-volume effects in our realization of lattice electrodynamics in chiral perturbation theory, and remaining finite-volume errors are relatively small. While electroquenched effects are under control for $\ensuremath{\epsilon}$, they are estimated only qualitatively for ${\ensuremath{\epsilon}}_{{K}^{0}}$ and constitute one of the largest sources of uncertainty for that quantity. We find $\ensuremath{\epsilon}=0.78(1{)}_{\text{stat}}(\genfrac{}{}{0}{}{+8}{\ensuremath{-}11}{)}_{\text{syst}}$ and ${\ensuremath{\epsilon}}_{{K}^{0}}=0.035(3{)}_{\text{stat}}(20{)}_{\text{syst}}$. We then use these results on $2+1+1$ flavor pure QCD highly improved staggered quark (HISQ) ensembles and find ${m}_{u}/{m}_{d}=0.4529(48{)}_{\text{stat}}(\genfrac{}{}{0}{}{+150}{\ensuremath{-}67}{)}_{\text{syst}}$.