Large-Scale Magnetic Fields from Density Perturbations