Git Product home page Git Product logo

imagebundle's Introduction

Gregwar's ImageBundle

paypal

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

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

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 => 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 architecture, you can create the config/packages/gregwar_image.yaml file with the following contents:

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

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 }}" />

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

<!-- The image some/image.jpg will be prefixed by web directory prefix -->
<img src="{{ web_image('some/image.jpg').resize('10%') }}" />

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

imagebundle's People

Contributors

gregwar avatar soullivaneuh avatar robbanl avatar emiliemarchand avatar takeno avatar mkurzeja avatar shulcsm avatar david-fanin avatar kenshaw avatar bondarovich avatar zausenec avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.