We investigate the generation of large scale magnetic fields in the universe from quantum fluctuations produced in the inflationary stage. By coupling these quantum fluctuations to the dilaton field and Ricci scalar, we show that the magnetic fields with the strength observed today can be produced. We consider two situations: First, the evolution of dilaton ends at the onset of the reheating stage. Second, the dilaton continues its evolution after reheating and then decays. In both cases, we come back to the usual Maxwell equations after inflation and then calculate present magnetic fields.