Skip to content

Commit

Permalink
Incorporate feedback from @wouterj
Browse files Browse the repository at this point in the history
  • Loading branch information
kix committed Oct 27, 2015
1 parent 925734c commit 28e0ab2
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions Resources/doc/basic-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ you want to thumbnail an image to a size of 120x90 pixels:
.. code-block:: yaml
# app/config/config.yml
liip_imagine:
resolvers:
default:
Expand All @@ -22,22 +21,22 @@ you want to thumbnail an image to a size of 120x90 pixels:
filters:
thumbnail: { size: [120, 90], mode: outbound }
You've now defined a filter set called `my_thumb` that performs a thumbnail transformation.
We'll learn more about available transformations later, but for now, this
new filter can be used immediately in a template:
You've now defined a filter set called `my_thumb` that performs a thumbnail
transformation. We'll learn more about available transformations later, but
for now, this new filter can be used immediately in a template:

.. code-block:: jinja
.. configuration-block:
<img src="{{ '/relative/path/to/image.jpg' | imagine_filter('my_thumb') }}" />
.. code-block:: html+jinja
Or if you're using PHP templates:
<img src="{{ '/relative/path/to/image.jpg'|imagine_filter('my_thumb') }}" />
.. code-block:: php
<img src="<?php $this['imagine']->filter('/relative/path/to/image.jpg', 'my_thumb') ?>" />
.. code-block:: html+php
<img src="<?php echo $this['imagine']->filter('/relative/path/to/image.jpg', 'my_thumb') ?>" />
Behind the scenes, the bundles applies the filter(s) to the image on the first
request and then caches the image to a similar path. On the next request,
Behind the scenes, the bundles applies the filter(s) to the image on the
first request and then caches the image to a similar path. On the next request,
the cached image would be served directly from the file system.

In this example, the final rendered path would be something like
Expand All @@ -46,49 +45,52 @@ would save the filtered image file.

You can also pass some options at runtime:

.. code-block:: jinja
.. configuration-block:
{% set runtimeConfig = {"thumbnail": {"size": [50, 50] }} %}
<img src="{{ '/relative/path/to/image.jpg' | imagine_filter('my_thumb', runtimeConfig) }}" />
.. code-block:: html+jinja
Or if you're using PHP templates:
{% set runtimeConfig = {"thumbnail": {"size": [50, 50] }} %}
<img src="{{ '/relative/path/to/image.jpg' | imagine_filter('my_thumb', runtimeConfig) }}" />
.. code-block:: php
.. code-block:: html+php
<?php
$runtimeConfig = array(
"thumbnail" => array(
"size" => array(50, 50)
)
);
?>
<?php
$runtimeConfig = array(
"thumbnail" => array(
"size" => array(50, 50)
)
);
?>
<img src="<?php $this['imagine']->filter('/relative/path/to/image.jpg', 'my_thumb', $runtimeConfig) ?>" />
<img src="<?php echo $this['imagine']->filter('/relative/path/to/image.jpg', 'my_thumb', $runtimeConfig) ?>" />
Also you can resolve image url from console:

.. code-block:: jinja
.. code-block:: bash
app/console liip:imagine:cache:resolve relative/path/to/image.jpg relative/path/to/image2.jpg --filters=my_thumb --filters=thumbnail_default
$ php app/console liip:imagine:cache:resolve relative/path/to/image.jpg relative/path/to/image2.jpg --filters=my_thumb --filters=thumbnail_default
Where only paths required parameter. They are separated by space. If you omit filters option will be applied all available filters.
Where only paths required parameter. They are separated by space. If you
omit filters option will be applied all available filters.

If you need to access filtered image URL in your controller:

.. code-block:: php
$this->get('liip_imagine.cache.manager')->getBrowserPath('/relative/path/to/image.jpg', 'my_thumb', true),
In this case, the final rendered path would contain some random data in the path
`/media/cache/my_thumb/S8rrlhhQ/relative/path/to/image.jpg`. This is where Imagine
would save the filtered image file.
In this case, the final rendered path would contain some random data in the
path ``/media/cache/my_thumb/S8rrlhhQ/relative/path/to/image.jpg``. This is where
Imagine would save the filtered image file.

.. 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:

.. code-block:: jinja
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:

.. code-block:: yaml
web_profiler:
intercept_redirects: false

0 comments on commit 28e0ab2

Please sign in to comment.