it-blaster/crop-bundle
Composer 安装命令:
composer require it-blaster/crop-bundle
包简介
The bundle for in-form image cropping
README 文档
README
This bundle is designed to create crops for images using the user-friendly UI in your forms. It uses the fengyuanchen/cropper jquery plugin and it-blaster/uploadable-bundle to handle images uploading.
Installation
Add it-blaster/crop-bundle to your composer.json file and run composer
... "require": { "it-blaster/crop-bundle": "1.0.*" } ...
Register the bundle in your AppKernel.php
... new Fenrizbes\CropBundle\FenrizbesCropBundle(), ...
Configure it-blaster/uploadable-bundle
Usage
1. Configure the CroppableBehavior for your table in schema.xml:
...
<behavior name="croppable">
<parameter name="columns" value="first_image, second_image" />
</behavior>
...
The parameter columns must contain one or more columns' names on which you want to apply this behavior
(default value: image). If your table contains other file-columns and you use the UploadableBundle to handle them,
don't worry: this bundle automatically adds its columns into UploadableBehavior configuration.
The CroppableBehavior creates two methods for each configured column:
setCroppable<column_name> and getCroppable<column_name>. (For example, if you configured the behavior as above,
in your base model will be created following methods: setCroppableFirstImage, getCroppableFirstImage,
setCroppableSecondImage and getCroppableSecondImage). You have to use this methods if you want to set up
the croppable FormType or get a cropped image.
2. Include bundle's resources in your page:
bundles/fenrizbescrop/lib/js/cropper.min.js- the cropper pluginbundles/fenrizbescrop/lib/css/cropper.min.css- cropper's stylesbundles/fenrizbescrop/js/croppable.js- bundle's scripts
Also remember that this bundle doesn't contain the JQuery library that's required for the cropper plugin.
3. Configure your form:
... ->add('CroppableFirstImage', 'croppable', array( 'width' => 250, 'height' => 250 )) ...
This construction adds a crop control for a picture in your form. Required parameters width and height set up
the minimum size of the crop area. You can read more about the croppable FormType's configuration in the relevant section.
After you upload an image, you'll see it with the crop area over it. Now you can select a part of the image and save crop coordinates.
4. The bundle contains a twig filter crop that provide you an ability to get a cropped image:
... <img src="{{ asset(item.croppableFirstImage | crop) }}" /> ...
If you configured a few crops for one picture, you can pass an index of the crop you want:
... <img src="{{ asset(item.croppableFirstImage | crop(1)) }}" /> ...
CroppableFormType configuration
The full set of specific parameters that you can pass to croppable field looks as follows:
... ->add('CroppableSecondImage', 'croppable', array( 'label' => 'Image crops', 'width' => 250, 'height' => 250, 'validate' => false, 'max_canvas_width' => 600, 'max_canvas_height' => 600, 'instances' => array( array( 'label' => 'First crop', 'width' => 200, 'height' => 250 ), array( 'label' => 'Second crop', 'width' => 100, 'height' => 100 ) ) )) ...
label
It's not a specific parameter but you need to know that this label display before all the field's controls.
width and height
Determine the default minimum size of the crop area. You can't select a part of image less than minimum.
validate
This parameter enables or disables validation for the image file. Validation constraints include a check of the
mime-type (only gif, png and jpg formats are allowed) and a check of minimum picture's size (the image can't be
less than the biggest of its crops). Default value: true.
max_canvas_width and max_canvas_height
These two values determine the max size of canvas in which will be inserted the original image and the crop control.
The original image will be scaled proportionally. If you want to disable this limitation, set 0 or false
to this options. Default values: 640 and 480 pixels.
instances
instances is a very important option. By default there is only one crop for each image. But if you want to do more
different crops for one image, you can configure them in this option. It must be an array of array. Each of them
describes one crop instance and takes three optional parameters:
label- the label for this crop (defaultnull)widthadnheight- the minimum size of the crop area for this crop (by default they inherit values from the basewidthadnheight)
TODO
- Delete previously generated and currently unused crops
it-blaster/crop-bundle 适用场景与选型建议
it-blaster/crop-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.04k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「image」 「propel」 「form」 「crop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 it-blaster/crop-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 it-blaster/crop-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 it-blaster/crop-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
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Bundle Symfony DaplosBundle
Free as in freedom php component that generates configuration based hard coded locator
统计信息
- 总下载量: 8.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-27