Fixing issue with file not being closed before being read by jpegtran