Do you mean create your own plugin? Of course, its entirely possible. Of course, no need to reinvent the wheel, there are plenty of plugins that will do this out of the box - you should check the plugins repositary. For example, nextgen gallery is quite popular. http://wordpress.org/extend/plugins/nextgen-gallery/
you can create a photo gallery by a gallery theme. i have made 4 of them: wordpressthemesbook.com/photo-gallery/ (wordphoto themes are mine).
does anyone know can you have the gallery work on wordpress like it works on facebook.. e.g meaning the page does not load every time I click on a new picture.