Change image style during hook_node_view() I'd like to programmatically change an image style during hook_node_view(), and I thought this would be relatively straightforward like so:

/**
 * Implements hook_node_view()
 */
function example_node_view($node, $view_mode, $langcode) {

  if (example_ok()) {
    $node-&gt;content['field_image'][0]['#image_style'] = 'new_image_style';
  }

}


Unfortunately this does not work. I'm aware of the picture and breakpoints modules, and am in fact using them, however there are sometimes when a dynamic decision needs to be made that these modules don't cover.
I hate to answer my own question, but this answer pointed me in the right direction. Here's the hook that worked in this case:

/**
 * Implements hook_preprocess_HOOK().
 */
function example_preprocess_image_style(&amp;$variables) {
  if (example_ok()) {
    $variables['style_name'] = 'new_image_style';  
  }
}

function example_ok() {
  global $user;
  // If the logged in user is bob, everything is ok.
  if ($user-&gt;uid &amp;&amp; $user-&gt;name == 'bob') {
    return TRUE;
  }
  return FALSE;
}