function for takingand saving images