Thumbnails are always jpg (or at least the few we saw were); so, if the original is some other type which can still generate a thumbnail, the code fails.