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 $approx 0.12$ fm to $approx 0.045$ fm. We compute the quantity $epsilon$, which parameterizes the corrections to Dashens theorem for the $K^+$-$K^0$ EM mass splitting, as well as $epsilon_{K^0}$, which parameterizes 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 $epsilon$, they are estimated only qualitatively for $epsilon_{K^0}$, and constitute one of the largest sources of uncertainty for that quantity. We find $epsilon = 0.78(1)_{rm stat}({}^{+phantom{1}8}_{-11})_{rm syst}$ and $epsilon_{K^0}=0.035(3)_{rm stat}(20)_{rm syst}$. We then use these results on 2+1+1 flavor pure QCD HISQ ensembles and find $m_u/m_d = 0.4529(48)_{rm stat}( {}_{-phantom{1}67}^{+150})_{rm syst}$.