Expected ‘add_filter’ (T_STRING)

You are dealing with a class. Most everything has to be inside a class method, not counting class variables/constants.

Second, you the syntax is slightly different when adding a class method, rather than a function, to a hook.

function widget( $args, $instance ) {
  add_filter('get_avatar', array($this,'remove_photo_class'));
  // the rest of your code
}

I would also edit your callback to remove itself:

function remove_photo_class($avatar) {
  remove_filter('get_avatar', array($this,'remove_photo_class'));
  return str_replace(' avatar', $image_align , $avatar);
}

Or explicitly remove it at the end of the widget method:

function widget( $args, $instance ) {
  add_filter('get_avatar', array($this,'remove_photo_class'));
  // the rest of your code
  remove_filter('get_avatar', array($this,'remove_photo_class'));
}

Or it might mess up things in other parts of the theme.