Skip to content

Commit

Permalink
resolve streams earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 27, 2018
1 parent 91e98cd commit 27df27d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Grav\Common\Data\Blueprint;
use Grav\Common\Grav;
use Grav\Common\Utils;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;

class ImageMedium extends Medium
{
Expand Down Expand Up @@ -152,12 +153,18 @@ public function path($reset = true)
*/
public function url($reset = true)
{
$image_path = Grav::instance()['locator']->findResource('cache://images', true);
$image_dir = Grav::instance()['locator']->findResource('cache://images', false);
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
$image_path = $locator->findResource('cache://images', true);
$image_dir = $locator->findResource('cache://images', false);
$saved_image_path = $this->saveImage();

$output = preg_replace('|^' . preg_quote(GRAV_ROOT) . '|', '', $saved_image_path);

if ($locator->isStream($output)) {
$output = $locator->findResource($output, false);
}

if (Utils::startsWith($output, $image_path)) {
$output = '/' . $image_dir . preg_replace('|^' . preg_quote($image_path) . '|', '', $output);
}
Expand Down

0 comments on commit 27df27d

Please sign in to comment.