Cannot instantiate interface DrupalStreamWrapperInterface I am trying to replace drupal_realpath with realpath. What I did is 

$stream_wrapper = new DrupalStreamWrapperInterface();
$file_path = $stream_wrapper-&gt;realpath($img_path);


But it gives me this error: Cannot instantiate interface DrupalStreamWrapperInterface. Any idea how do I use DrupalStreamWrapperInterface::realpath?
The error is because you are trying to create an object of a PHP Interface, which is not allowed in PHP. You can only create objects from a PHP Class.

To solve your issue, something like this might work:

$wrapper = file_stream_wrapper_get_instance_by_uri($img_path);
if (is_object($wrapper)) {
  $file_path = $wrapper-&gt;realpath();
}