presta/image-bundle
Composer 安装命令:
composer require presta/image-bundle
包简介
PrestaImageBundle is a Symfony bundle providing tools to resize uploaded and remote images before sending them through a classic form.
README 文档
README
Overview
PrestaImageBundle is a Symfony bundle providing tools to resize uploaded and remote images before sending them through a classic form. It uses the Cropper.js library.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require presta/image-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require presta/image-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
// config/bundles.php return [ // ... Presta\ImageBundle\PrestaImageBundle::class => ['all' => true], ];
Configuration
You must configure the form_layout.html.twig form theme into config/packages/twig.yaml.
twig: form_themes: - "@PrestaImage/form/form_layout.html.twig"
Note: you can also create your own form theme instead.
You must include the routing into config/routes.yaml:
presta_image: resource: "@PrestaImageBundle/config/routing.yaml"
See VichUploader documentation to configure the bundle.
Assets
See Cropper.js documentation to install assets.
Don't forget to include the following assets in your page:
@PrestaImageBundle/public/css/cropper.css@PrestaImageBundle/public/js/cropper.js
How to: implementation examples
Usage
Initialize cropper
document.querySelectorAll('.presta-image').forEach(element => { new Cropper(element) })
Use the form type
<?php use Presta\ImageBundle\Form\Type\ImageType; public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add('image', ImageType::class) ; }
Available options for the ImageType:
aspect_ratios(array): a list of aspect ratio to apply when resizing an imagecropper_options(array): a list of options supported by cropper (default:['autoCropArea' => 1])max_width(int): the max width of the cropped image send to server (default:320)max_height(int): the max height of the cropped image send to server (default:180)preview_width(string): the max width to use when displaying the image preview - can be in px, % or other css value (default:'320px')preview_height(string): the max height to use when displaying the image preview - can be in px, % or other css value (default:'180px')upload_button_class(string): CSS class of the "upload" button (default:'')cancel_button_class(string): CSS class of the "cancel" button (default:'')save_button_class(string): CSS class of the "save" button (default:'')download_uri(string): the path where the image is located (default:null, automatically set)show_image(bool): whether the image should be rendered in the form or not (default:true)file_upload_enabled(bool): whether to enable the file upload widget or not (default:true)remote_url_enabled(bool): whether to enable the remote url widget or not (default:true)rotation_enabled(bool): whether to enable the rotation or not (default:false)upload_mimetype(string): format of the image to be uploaded (default:image/png)
(Note: If the chosen mimetype is not supported by the browser, it will silently fall back toimage/png)upload_quality(float): quality (0..1) of uploaded image for lossy imageformats (eg.image/jpeg) (default:0.92)
Notes
You can find Cropper.js options here.
The max_width and max_height options are used to define maximum size the cropped uploaded image will be.
Bigger images (after cropping) are scaled down.
Security Note: NEVER rely on this size constraints and the format settings as
they can easily be manipulated client side. ALWAYS validate the image-data, image-size, image-format server side!
Contributing
Pull requests are welcome.
Thanks to everyone who has contributed already.
This project is supported by PrestaConcept
Lead Developer : @J-Ben87
Released under the MIT License
presta/image-bundle 适用场景与选型建议
presta/image-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 159.32k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2016 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「image」 「form」 「bundle」 「upload」 「remote」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 presta/image-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 presta/image-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 presta/image-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
A Laravel Filament Forms slug field.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 159.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 25
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-01