Why bother with $temp_file?  It seems like you could just unlink $output_file and then let the events operate on it and if an event creates the output file then you'red one - no moving required.  So the logic would be:

```
unlink($output_file);
module::event("graphics_rotate", $input_file, $output_file, ...);
if (!file_exists($output_file) || filesize($output_file) == 0) {
  // do the old operations
}
```