elendev/image-bundle

提供简单的图像处理工具,用于调整图像大小

安装: 574

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 4

分支: 1

开放问题: 0

类型:symfony-bundle

1.1.11 2018-09-16 08:47 UTC

This package is auto-updated.

Last update: 2024-09-09 13:32:35 UTC


README

包配置

elendev_image:
    cache_dir: 'path_to_cache_directory'
	source_dir: 'path_to_image_dir'
	cache_url: 'url/to/cache/dir'

配置键 cache_dir 是缓存目录的本地路径。它是生成文件存储的目录(例如:/var/www/my-website/media/cache)。

配置键 source_dir 是包含图像的目录的本地路径(例如:/var/www/my-website/media/original-files)。

配置键 cache_url 是缓存目录的 URL。如果 URL http://www.my-website.com 重定向到本地 /var/www/my-website 目录,则此配置键的值将是 http://www.my-website.com/media/cache

使用 Twig 的扩展图像方法

<img src="{{image('source')}}"/>

<img src="{{image('source').resize(200, 200)}}"/>

<img src="{{image('source').rotate(180).greyScale()}}"/>

可用方法是 Elendev\ElendevImageBundle\ImageProxy 类的方法

interface ImageProxy {

    ...
    
    public function resize($width, $height, $keepRatio = true, $allowEnlarge = false);
    
    /**
     * @param type $degree
     * @param type $bgcolor background color for visible parts, by default black
     */
    public function rotate($degree, $bgcolor = 0);
    
    /**
     * Do greyscale on picture
     */
    public function greyScale();

    ...

}