Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added optional support for generating absolute paths

  • Loading branch information...
commit 8884e08dbdc59d4b7b91b670967639de5e74a1c1 1 parent b00818e
@lsmith77 lsmith77 authored
View
5 Imagine/CachePathResolver.php
@@ -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));
@@ -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;
View
13 README.md
@@ -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
View
5 Templating/Helper/ImagineHelper.php
@@ -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);
}
/**
View
5 Templating/ImagineExtension.php
@@ -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);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.