An alternative method to this would be to check for the 'If-Modified-Since' request header as it will only be present if the browser already has the file.
If it is present, then you know the file is already created and can respond with a link to it, otherwise run your code above. Something like this...
// check if the client validating cache and if it is current
if ( isset( $headers['If-Modified-Since'] ) && ( strtotime( $headers['If-Modified-Since'] ) == filemtime( $image->get_full_path() ) ) ) {
// cache IS current, respond 304
header( 'Last-Modified: ' . $image->get_last_modified(), true, 304 );
} else {
// not cached or client cache is older than server, respond 200 and output
header( 'Last-Modified: ' . $image->get_last_modified(), true, 200 );
header( 'Content-Length: ' . $image->get_filesize() );
header( 'Cache-Control: max-age=' . $image->get_expires() );
header( 'Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + $image->get_expires() ) );
header( 'Content-Type: image/jpeg');
print file_get_contents( $image->get_full_path() );
}