Skip to content

Commit

Permalink
added optional support for generating absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Oct 20, 2011
1 parent b00818e commit 8884e08
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Imagine/CachePathResolver.php
Expand Up @@ -45,8 +45,9 @@ public function __construct(RouterInterface $router, Filesystem $filesystem, $we
*
* @param string $path
* @param string $filter
* @param boolean $absolute
*/
public function getBrowserPath($targetPath, $filter)
public function getBrowserPath($targetPath, $filter, $absolute = false)
{
if (0 === strpos($targetPath, $this->webRoot)) {
$targetPath = substr($targetPath, strlen($this->webRoot));
Expand All @@ -57,7 +58,7 @@ public function getBrowserPath($targetPath, $filter)
$path = str_replace(
urlencode($params['path']),
urldecode($params['path']),
$this->router->generate('_imagine_'.$filter, $params)
$this->router->generate('_imagine_'.$filter, $params, $absolute)
);

return $path;
Expand Down
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -134,10 +134,23 @@ In this example, the final rendered path would be something like
`/media/cache/my_thumb/relative/path/to/image.jpg`. This is where Imagine
would save the filtered image file.

In order to get an absolute path to the image add another parameter with the value true:

``` jinja
<img src="{{ '/relative/path/to/image.jpg' | imagine_filter('my_thumb', true) }}" />
```

Or if you're using PHP templates:

``` php
<img src="<?php $this['imagine']->filter('/relative/path/to/image.jpg', 'my_thumb', true) ?>" />
```

Note: Using the ``dev`` environment you might find that the images are not properly rendered when
using the template helper. This is likely caused by having ``intercept_redirect`` enabled in your
application configuration. To ensure that the images are rendered disable this option:


``` jinja
web_profiler:
intercept_redirects: false
Expand Down
5 changes: 3 additions & 2 deletions Templating/Helper/ImagineHelper.php
Expand Up @@ -27,12 +27,13 @@ public function __construct(CachePathResolver $cachePathResolver)
*
* @param string $path
* @param string $filter
* @param boolean $absolute
*
* @return string
*/
public function filter($path, $filter)
public function filter($path, $filter, $absolute = false)
{
return $this->cachePathResolver->getBrowserPath($path, $filter);
return $this->cachePathResolver->getBrowserPath($path, $filter, $absolute);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions Templating/ImagineExtension.php
Expand Up @@ -38,12 +38,13 @@ public function getFilters()
*
* @param string $path
* @param string $filter
* @param boolean $absolute
*
* @return string
*/
public function filter($path, $filter)
public function filter($path, $filter, $absolute = false)
{
return $this->cachePathResolver->getBrowserPath($path, $filter);
return $this->cachePathResolver->getBrowserPath($path, $filter, $absolute);
}

/**
Expand Down

0 comments on commit 8884e08

Please sign in to comment.