prolix / image-bundle
允许在通过经典表单上传之前裁剪本地和远程图像。
3.0.0
2020-07-13 14:12 UTC
Requires
- php: >=5.5.9
- symfony/form: ^3.4|^4.0|^5.0
- vich/uploader-bundle: 1.15.*
README
概述
PrestaImageBundle是一个提供工具,在通过经典表单上传之前调整本地/远程图像大小的Symfony包。它使用Cropper jQuery插件。
安装
将包作为Composer依赖项要求
php composer.phar require presta/image-bundle
在内核中启用包
您必须在app/AppKernel.php
中添加以下包
<?php public function registerBundles() { $bundles = [ // ... new Vich\UploaderBundle\VichUploaderBundle(), new Presta\ImageBundle\PrestaImageBundle(), ]; }
配置包
您必须在app/config.yml
中使用image_widget.html.twig
表单主题。
twig: form_themes: - "PrestaImageBundle:form:image_widget.html.twig"
您必须将路由包含到app/config/routing.yml
presta_image: resource: "@PrestaImageBundle/Resources/config/routing.yml"
有关配置包的详细信息,请参阅VichUploader 文档。
安装资产
有关安装资产的详细信息,请参阅Cropper 快速入门部分。
不要忘记在您的页面上包含以下资产
/path/to/cropper/dist/cropper.min.css
/path/to/cropper/dist/cropper.min.js
@PrestaImageBundle/Resources/public/css/cropper.css
@PrestaImageBundle/Resources/public/js/cropper.js
用法
初始化裁剪器
(function(w, $) { 'use strict'; $(function() { $('.cropper').each(function() { new Cropper($(this)); }); }); })(window, jQuery);
使用表单类型
<?php use Presta\ImageBundle\Form\Type\ImageType; public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('image', ImageType::class) ; }
ImageType
的可用选项
aspect_ratio
(array
):调整图像大小时应用的宽高比列表cropper_options
(array
):裁剪器支持的一组选项(默认:['autoCropArea' => 1]
)max_width
(int
):发送到服务器的裁剪图像的最大宽度(默认:320
)max_height
(int
):发送到服务器的裁剪图像的最大高度(默认:180
)preview_width
(int
):显示图像预览时使用的最大宽度(默认:320
)preview_height
(int
):显示图像预览时使用的最大高度(默认:180
)download_uri
(string
):图像所在的路径(默认:null
,自动设置)download_link
(bool
):最终用户是否应该能够通过URL添加远程图像(默认:true
)upload_mimetype
(string
):要上传的图像的格式(默认:image/png
)
(注意:如果选择的MIME类型不受浏览器支持,它将静默回退到image/png
)upload_quality
(float
):上传图像的损失图像格式的质量(0..1)(默认:0.92
)
注意
您可以在此处找到Cropper选项。
使用max_width
和max_height
选项定义裁剪上传图像的最大尺寸。更大的图像(裁剪后)将被缩小。
安全注意:永远不要依赖于这些尺寸限制和格式设置,因为它们很容易在客户端被操纵。始终在服务器端验证图像数据、大小和格式!
贡献
欢迎提交拉取请求。
感谢所有已作出贡献的人。
该项目由PrestaConcept支持。
主要开发者 : @J-Ben87
在MIT许可下发布