  Magnetar bursts can be emitted by Alfv\'en waves growing in the outer
magnetosphere to nonlinear amplitudes, $\delta B/B\sim 1$, and triggering
magnetic reconnection. Similar magnetic flares should occur quasi-periodically
in a magnetized neutron star binary nearing merger. In both cases, fast
dissipation in the magnetic flare creates optically thick $e^\pm$ plasma, whose
heat capacity is negligible compared with the generated radiation energy.
Magnetic dissipation then involves photon viscosity and acts through Compton
drag on the plasma bulk motions in the reconnection region. The effective
temperature of the resulting Comptonization process is self-regulated to tens
of keV. The generated X-ray emission is calculated using time-dependent
radiative transfer simulations, which follow the creation of $e^\pm$ pairs and
the production, Comptonization, and escape of photons. The simulations show how
the dissipation region becomes dressed in an $e^\pm$ coat, and how the escaping
spectrum is shaped by radiative transfer through the coat. The results are
compared with observed magnetar bursts, including the recent activity of SGR
1935+2154 accompanied by a fast radio burst. Predictions are made for X-ray
precursors of magnetized neutron star mergers.
