Work distribution in a photonic system