symfony处理图片的bundle,其中比较有用的就是生成缩略图,以及将图片缓存
composer require liip/imagine-bundle
安装过程中会让用户选择,这里选择y
然后项目会自动注入依赖,配置文件等,不需要手动引入
最后的配置文件在: app/config/packages/liip_imagine.yaml 而不是demo里的 app/config/config.yml
//liip_imagine.yaml 添加需要的配置如下
# Documentation on how to configure the bundle can be found at: https://symfony.com/doc/current/bundles/LiipImagineBundle/basic-usage.html
liip_imagine:
# valid drivers options include "gd" or "gmagick" or "imagick"
driver: "imagick"
webp:
generate: true
filter_sets:
squared_thumbnail_small:
filters:
thumbnail:
size: [200, 200]
mode: outbound
allow_upscale: true
loaders:
default:
filesystem:
data_root:
- "%kernel.project_dir%/public"
twig模板使用:src="{{ asset(course.coverPicture)|imagine_filter('squared_thumbnail_small') }}
