I think we should figure out why it "crashes" since there might be a bug also. I do not think that you really need to build logic to determine/set file extensions. The only things that this functionality should be aware of are: image data and size set. It's up to you to decide if you want to generate the new file names based on the filer file name or not. The file extensions are irrelevant in this exact specific case. You can generate the new file names like this <some_cropduster_location>_<random_number>_<timestamp><file extension if you really want it>.