camelot / image-asset
基于GD处理图片缩略图的图像管理库和捆绑包
dev-master
2019-11-13 03:36 UTC
Requires
- php: ^7.1
- ext-fileinfo: *
- ext-gd: *
- ext-json: *
- camelot/thrower: ^1.0
- contao/imagine-svg: ^0.1
- miljar/php-exif: ^0.6.5
- symfony/filesystem: ^4.3 || ^5.0
- symfony/finder: ^4.3 || ^5.0
- symfony/mime: ^4.3 || ^5.0
- webmozart/path-util: ^2.3
Requires (Dev)
- camelot/coding-style: ^2.0
- friendsofphp/php-cs-fixer: ^2.16
- symfony/asset: ^4.3 || ^5.0
- symfony/browser-kit: ^4.3 || ^5.0
- symfony/console: ^4.3 || ^5.0
- symfony/css-selector: ^4.3 || ^5.0
- symfony/debug-bundle: ^4.3 || ^5.0
- symfony/dotenv: ^4.3 || ^5.0
- symfony/framework-bundle: ^4.3 || ^5.0
- symfony/phpunit-bridge: ^4.3 || ^5.0
- symfony/security-bundle: ^4.3 || ^5.0
- symfony/twig-bundle: ^4.3 || ^5.0
- symfony/yaml: ^4.3 || ^5.0
- twig/twig: ^2.10 || ^3.0
- vimeo/psalm: ^3.4
This package is auto-updated.
Last update: 2024-09-18 21:29:22 UTC
README
安装
使用Symfony Flex的应用程序
打开命令行控制台,进入您的项目目录并执行
$ composer require camelot/image-asset
不使用Symfony Flex的应用程序
步骤 1:下载捆绑包
打开命令行控制台,进入您的项目目录并执行以下命令以下载此捆绑包的最新稳定版本
$ composer require camelot/image-asset
此命令需要您全局安装Composer,具体请参阅Composer文档中的安装章节。
步骤 2:启用捆绑包
然后,通过将其添加到项目中 config/bundles.php
文件中注册的捆绑包列表来启用捆绑包
// config/bundles.php return [ // ... Camelot\ImageAsset\Bridge\Symfony\CamelotImageAssetBundle::class => ['all' => true], ];
配置
默认配置
# config/packages/camelot_image_asset.yaml camelot_image_asset: image_dirs: - '%kernel.project_dir%/public/images' static_path: '%kernel.project_dir%/public/thumbs' routing: mount_point: /thumbs image: controller: Camelot\ImageAsset\Controller\ImageController path: '/{width}x{height}/{action}/{file}' image_alias: controller: Camelot\ImageAsset\Controller\ImageAliasController path: '/{alias}/{file}' default_image: path: image-default.png filesystem: camelot.image.filesystem.bundle default_image_size: width: 1024 height: 768 error_image: path: image-error.png filesystem: camelot.image.filesystem.bundle cache_time: null limit_upscaling: true only_aliases: false aliases: ~
别名
# config/packages/camelot_image_asset.yaml camelot_image_asset: # ... aliases: my_alias: image_size: width: 1024 height: 768 action: ~ # One of "border"; "crop"; "fit"; "resize" other_alias: image_size: width: 1900 height: 1200 action: ~ # One of "border"; "crop"; "fit"; "resize"
路由
# config/routes/camelot_image_asset.yaml camelot_image_asset: resource: . type: image_asset prefix: /
用法
Twig
{% set uri = '/images/image.png' %} {# This will be cropped to the default width & height #} <img src="{{ thumbnail(uri, my_alias) }}"> {# Same, but path resolved by Symfony's asset() Twig function #} {% set package_name = 'my_symfony_asset_package_name' %} # See config/packages/assets.yaml <img src="{{ thumbnail(asset(uri, package_name), my_alias) }}">
NGINX优化
location ~* /thumbs/(.*)$ { try_files $uri $uri/ /index.php?$query_string; } location ~* ^.+\.(?:gif|jpe?g|jpeg|jpg|png|svg|svgz)$ { access_log off; log_not_found off; expires max; add_header Access-Control-Allow-Origin "*"; add_header Cache-Control "public, mustrevalidate, proxy-revalidate"; add_header Pragma public; }