finished gallery script for proper image resizing