Developed with love by KnpLabs Hire us for your project!
78

ImageBundle

by Gregwar

Image manipulation bundle for Symfony 2

Gregwar's ImageBundle

GregwarImageBundle provides easy Image manipulation and API for Symfony2 and Twig

Installation

Step 1: Download the GregwarImageBundle

Using the vendors script

Add the following lines to your deps file:

    [GregwarImageBundle]
        git=http://github.com/Gregwar/ImageBundle.git
        target=/bundles/Gregwar/ImageBundle

Now, run the vendors script to download the bundle:

$ php bin/vendors install

Using submodules

If you prefer instead to use git submodules, then run the following:

$ git submodule add git://github.com/Gregwar/ImageBundle.git vendor/bundles/Gregwar/ImageBundle
$ git submodule update --init

Using Composer

Add the following to the "require" section of your composer.json file:

    "gregwar/image-bundle": "dev-master"

You can also choose a version number, (tag, commit ...)

And update your dependencies

    php composer.phar update

Step 2: Configure the Autoloader

If you use composer, you can skip this step.

Add it to your autoload.pp :

<?php
...
'Gregwar' => __DIR__.'/../vendor/bundles',

Step 3: Enable the bundle

Registers the bundle in your app/AppKernel.php:

<?php
...
public function registerBundles()
{
    $bundles = array(
        ...
        new Gregwar\ImageBundle\GregwarImageBundle(),
        ...
    );
...

Step 4: 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

Usage

Basics

This bundle is based on the Gregwar's Image class and
provides simple but powerful Twig extension. You can for instance use it this way:

<img src="{{ image('linux.jpg').resize(100,100).negate }}" />

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.

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

<img src="{{ image('@AcmeDemoBundle/Resources/images/linux.jpg').resize(100,100).negate }}" />

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

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

<?php
...
$this->get('image.handling')->open('linux.jpg')
    ->grayscale()
    ->rotate(12)
    ->save('out.jpg')

Requirements

GregwarImageBundle needs GD
and exif extension for PHP to be installed on the web server

License

This bundle is under MIT license

Copyright (c) <2012> Grégoire Passault

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  • Adding @ on GD calls to avoid warnings (see #22)
    By Gregwar, 11 days ago
  • Merge pull request #22 from shulcsm/patch-1
    By Gregwar, 11 days ago
  • Suppress warning for imagecreatefromstring()
    By , 11 days ago
  • imagecreatefromstring() error handling
    By shulcsm, 13 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago
  • Adding bundle logical (@) notation (fixes #18)
    By Gregwar, 25 days ago