with jpg file creation. OLD VERSION