Added a capture_preview() function that will write a preview directly to a file