used Apple sample code for image gallery