Symfony2 image tag. Add colored tags with label to your image on symfony 2.3.

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language: JavaScript

Type: symfony-bundle

2.3 2013-08-26 22:26 UTC


The ImageTagBundle allows you to add tags to your images. Tags takes the form of a box of a different color followed by a label. Tags are stored in your database every times you make a change on it.

To use it, the bundle provide:

  • A twig function for creating tags
  • A twig function to display images with their tags.


  • This bundle has been tested on Firefox, Chrome, Safari and Symfony 2.3.x
  • Thank you to share all issues regarding this bundle


Using composer file with Symfony 2.3.x :

"require": {
    "palap/imagetag-bundle": "dev-master"

Subsequently add the following line to AppKernel.php :

new Palap\ImageTagBundle\PalapImageTagBundle(),

In app/config/routing.yml add the following:

    resource: "@PalapImageTagBundle/Resources/config/routing.yml"
    prefix: imagetag/

In your HTML file, add those lines:

<!-- Jquery and CSS in the header part of your HTML -->
<script src="//"></script>
<script src="//"></script>
<link rel="stylesheet" href="{{ asset('bundles/palapimagetag/css/imagetag.css') }}" />
<link rel="stylesheet" href="" />

<!-- This last one can be include at the end -->
<script type="text/javascript" src="{{ asset('bundles/palapimagetag/js/imagetag.js') }}" ></script>

And don't forget to run those 3 commands:

app/console doctrine:schema:update --force
app/console assets:install --symlink web
app/console assetic:dump --env=prod

Simple usage

Adding tags

Note: 'theScope' must be different for every image you want to display on a same document. It's an HTML Id.

{{ setImageTag (
    'optional - Image Alt property'
) }}

Explanation :

  • The first parameter is the path of the picture, it is possible to use any twig function returning a path as GregwarImageBundle functions.
  • The second parameter will be used as Scope to allow the js script distinguishes different images.
  • Tags associated with images considering the file name, the width and height of the image.
  • Creating tags is secure according to the following role : IS_AUTHENTICATED_FULLY, you can change it by extending the bundle controller.
Display tags
{{ imageTag (
    'optional - Image Alt property'
) }}

Usage with custom controller

It is possible to use a controller with twig custom functions to modify the way the script will save the tags.

Adding tags - custom controller

{{ setImageTag (
    'Not optional - Image Alt property',
    path('MyCustomControllerRoute', {'id', 'fieldName':'file', 'otherUsefulParameters':parameters})
) }}

Explanation :

  • MyCustomControllerRoute is the route used by the Ajax request
  • You must definitely specify a parameter in your way, even if it is a decoy to initiate the "query string"
  • The query string added to your Route by the script js is as follows :

    '&init=' + init + '&width=' + imageWidth + '&height=' + imageHeight
    + '&htmlcontent=' + encodeURIComponent($('.tagz', context).html())
  • init is equal to true on the first query, used for initialization purpose

  • htmlcontent contains tags to save

Display tags - custom controller

{{ imageTag (
    'Not optional - Image Alt property',
    path('MyCustomControllerRoute', {'id', 'fieldName':'file', 'otherUsefulParameters':parameters})
) }}


Displaying tags

If you only need to display the tags you're free to only include imagetag-display.js.

In that file I also include the showTags({{theScope}}) and hideTags({{theScope}}) js function that will help you to hide and display all tags at once.