PHPackages                             gregwar/image-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. gregwar/image-bundle

ActiveSymfony-bundle[Image &amp; Media](/categories/media)

gregwar/image-bundle
====================

Image handling bundle

v3.0.2(3y ago)1941.5M↓22.4%49[31 issues](https://github.com/Gregwar/ImageBundle/issues)[3 PRs](https://github.com/Gregwar/ImageBundle/pulls)9MITPHPPHP &gt;=5.3.3

Since Apr 9Pushed 3y ago12 watchersCompare

[ Source](https://github.com/Gregwar/ImageBundle)[ Packagist](https://packagist.org/packages/gregwar/image-bundle)[ Docs](https://github.com/Gregwar/ImageBundle)[ RSS](/packages/gregwar-image-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (36)Used By (9)

Gregwar's ImageBundle
=====================

[](#gregwars-imagebundle)

[![paypal](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YUXRLWHQSWS6L)

`GregwarImageBundle` provides easy Image manipulation and API for Symfony and Twig

If you use older version than Symfony 4, please use the `2.*` version, else you can use `3.*`.

Installation
============

[](#installation)

### Step 1: Download the GregwarImageBundle

[](#step-1-download-the-gregwarimagebundle)

Run the following composer command:

```
    composer req gregwar/image-bundle

```

### Step 2: Configure the bundle and set up the directories

[](#step-2-configure-the-bundle-and-set-up-the-directories)

Adds the following configuration to your `app/config/config.yml`:

```
gregwar_image: ~

```

If you want to customize the cache directory name, you can specify it:

```
gregwar_image:
    cache_dir:  my_cache_dir

```

Creates the cache directory and change the permissions so the web server can write in it:

```
mkdir web/cache
chmod 777 web/cache

```

You can also enable the exception thrown if the given file does not exist:

```
gregwar_image:
    throw_exception: true

```

If you don't throw an exception, you can set the `fallback_image`, to set the image that should be rendered in this case:

```
gregwar_image:
    fallback_image: /path/to/your/fallback.jpg

```

If you have to change directories hierarchy or Web's name (e.g. web =&gt; public\_html), you can set the `web_dir` to your new Web path:

```
gregwar_image:
    web_dir: %kernel.root_dir%/../../public_html

```

With Symfony Flex
-----------------

[](#with-symfony-flex)

With Symfony Flex architecture, you can create the `config/packages/gregwar_image.yaml`file with the following contents:

```
gregwar_image:
    web_dir: %kernel.root_dir%/../public

```

Usage
=====

[](#usage)

Basics
------

[](#basics)

This bundle is based on the [Gregwar's Image](http://github.com/Gregwar/Image) class and provides simple but powerful Twig extension. You can for instance use it this way:

```

```

And that's all ! The helper will automatically create the cached file on-the-fly if it doesn't exists yet.

The available methods are the same as the [Gregwar's Image](http://github.com/Gregwar/Image).

You can also use the logical file names for bundle resources :

```

```

If you use `web_image()` helper, the image file path will be prefixed by the `web/` absolute directory of your application:

```

```

Using Image API
---------------

[](#using-image-api)

The image instance provides also a simple API, you can call some methods to get informations about the handled image:

```
Image width: {{ image('linux.jpg').width }}px

```

Manipulating Image in Controllers
---------------------------------

[](#manipulating-image-in-controllers)

The Image Handler is accessible via a service called image.handling. So you can do in your controllers:

```
