承接 it-blaster/crop-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

it-blaster/crop-bundle

Composer 安装命令:

composer require it-blaster/crop-bundle

包简介

The bundle for in-form image cropping

README 文档

README

Scrutinizer Code Quality Build Status License Total Downloads Latest Unstable Version Latest Stable Version

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 plugin
  • bundles/fenrizbescrop/lib/css/cropper.min.css - cropper's styles
  • bundles/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 (default null)
  • width adn height - the minimum size of the crop area for this crop (by default they inherit values from the base width adn height)

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 it-blaster/crop-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 7
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-27