Symfony 2 的图像处理套件
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.*.
Run the following composer command:
composer req gregwar/image-bundleAdds 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_dirCreates the cache directory and change the permissions so the web server can write in it:
mkdir web/cache
chmod 777 web/cacheYou can also enable the exception thrown if the given file does not exist:
gregwar_image:
throw_exception: trueIf 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.jpgIf 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_htmlWith Symfony Flex architecture, you can create the config/packages/gregwar_image.yaml
file with the following contents:
gregwar_image:
web_dir: %kernel.root_dir%/../publicThis bundle is based on the Gregwar's 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.
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:
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 }}pxThe Image Handler is accessible via a service called image.handling. So you can do in your controllers:
get('image.handling')->open('linux.jpg')
->grayscale()
->rotate(12)
->save('out.jpg')GregwarImageBundle needs GD
and exif extension for PHP to be installed on the web server
This bundle is under MIT license
暂无开放 Issues,或尚未同步最近议题。