Is it possible to use an image style with a path rather than a URI? I want to be able to send an image included in a custom module to the image_style theme like:

  $render_image = [
    '#theme' =&gt; 'image_style',
    '#style_name' =&gt; $imagecache_template,
    '#uri' =&gt; '/modules/custom/MYMODULE/default.png',
    ...
  ];


But '#uri' is expecting something in the format public:// . Is it possible to marshall a relative path somehow?
I'll expand a bit on what acrosman answered, only because I needed this exact same thing so hopefully this will help the next person who comes across this.

I'm working from preprocess_page and using a view to grab my images.

Like his answer make sure you add the ImageStyle:

use Drupal\image\Entity\ImageStyle;


Once I grabbed the view entity I was able to narrow down my image field and then work my way to the styled image. 

$image = $entity-&gt;get('field_images')-&gt;getValue();
$image_entity = File::load($image[0]['target_id']);
$image_uri = $image_entity-&gt;get('uri')-&gt;value;
$style = ImageStyle::load('my_image_style');
$image_url = $style-&gt;buildUrl($image_uri);


So overall my whole function to grab the image from a View and apply a custom image style looked like.

function _mytheme_preprocess_page_front_projects(array &amp;$variables) {
  $projects = array();
  $view = Views::getView('projects');

  if (is_object($view)) {
    $view-&gt;setDisplay('page_1');
    $view-&gt;preExecute();
    $view-&gt;execute();

    foreach ($view-&gt;result as $k =&gt; $v) {
      $entity = $v-&gt;_entity;

      // Grab image entity.
      $image = $entity-&gt;get('field_images')-&gt;getValue();

      // Load the first value for preview image.
      $image_entity = File::load($image[0]['target_id']);

      // Grab the uri of that first image.
      $image_uri = $image_entity-&gt;get('uri')-&gt;value;

      // Using ImageStyle you then load your style.
      $style = ImageStyle::load('my_image_style');

      // Use buildUrl to create the path to your styled image.
      $image_url = $style-&gt;buildUrl($image_uri);

      // Then I return the url as an image variable to grab in page template.
      $projects[$k]['image'] = $image_url;
    }

    return $projects;
  }
}