定制 willmorgan/silverstripe-cropperfield 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

willmorgan/silverstripe-cropperfield

最新稳定版本:2.0.0

Composer 安装命令:

composer require willmorgan/silverstripe-cropperfield

包简介

Provides an interface for you to generate thumbnails of things in the CMS. Adapters can be used to extend the functionality to thumbnail videos, PDF documents, etc.

README 文档

README

Build Status

Do you need to crop your images for art direction purposes?

Perhaps this is for responsive design, or perhaps you're tired of CroppedResize, PaddedResize, Square and general centre-based resizing functionality in SilverStripe that doesn't quite meet your image cropping needs.

Maybe CropperField is for you. Whilst it's called CropperField, that's just the user interface. Behind the scenes, a clean and extensible architecture allows you to crop almost anything - external URLs, documents, video frames, etc..

For the field itself, the frontend is powered by Cropper v0.7.5 by Fengyuan Chen.

Warning: Under development / alpha. Do not use unless you are prepared to contribute!

Installation

  1. composer require willmorgan/silverstripe-cropperfield
  2. Specify a version constraint.
  • While this module is in heavy development, you probably want to use ~0.X or similar.

Screenshot

The field currently looks like this in a CMS setting.

Screenshot of the field

Usage

  1. Specify a $has_one Image relationship on the object that should own the cropped image.
  2. Specify an image based UploadField whose image you wish to crop.
  • Only UploadField is supported right now. Non-images will break. Sorry.
  1. Create an AdapterInterface implementor to pass into your CropperField
  • See [1]; the adapters are generic enough for you to supply anything - as long as there's a File object backing it (regardless of whether it exists).
  1. Set some options, if you so desire.
  2. Happy cropping.

Example

In this example, a configuration like this has been set up:

$has_one = array(
	'MyBigPhoto' => 'Image',
	'MyArtDirectionCrop' => 'Image',
);

Inside a getCMSFields call, or similar:

$uploadField = new UploadField('MyBigPhoto', 'Big Photo Uploader');
$cropperField = new CropperField\CropperField(
	'MyArtDirectionCrop',
	'Cropped Image',
	new CropperField\Adapter\UploadField(
		$uploadField
	)
);

You can now use $MyArtDirectionCrop in your template as you would any other image (i.e. you can use $ResizeRatio, $Square, etc.)

The initial benefit is the CMS user gets to specify the true focus point of a potentially high resolution image, and you / your frontend team can reuse that base cropped image responsively, be it using srcset, picture + source, etc.

Options

You can set these options on the CropperField to get some control over your CMS users' actions.

Option name Value example Default value Description
aspect_ratio null or positive float, like 16/9 null The aspect ratio you want generated cropped images to have.
crop_min_width Positive integer, like 256 256 The minimum dimensions a crop can be, in px.
crop_min_height Positive integer, like 256 256
crop_max_width null or positive integer null Maximum dimensions a crop can be, in px.
Blank by default because this restricts the art direction somewhat. If you wish to limit the actual generated size of the cropped image, set generated_max_* instead.
crop_max_height null or positive integer null
generated_max_width Positive integer, like 512 512 The maximum dimensions a generated image can be, in px.
If the crop is above this, then it will be downscaled according to the declared aspect ratio, or the implied aspect ratio if one is not specified.
generated_max_height Positive integer, like 512 512

Supplied Adapters

  • CropperField\Adapter\UploadField for image based upload fields

Supplied Croppers

  • CropperField\Cropper\GD for GD installations
  • Imagick coming soon

Customisation

  • Templates: you can easily customise the template used - just override CropperField.ss
  • You can write your own croppers (say, for Imagick).
    1. Implement the CropperInterface
    2. Either set it on a per-instance basis using CropperField->setCropper()
    3. Set it in YML, overriding CropperFactory.cropper. The factory uses Injector for DI.

Compatibility

  • While Cropper is able to support browsers as old as IE8, the CropperField CMS UI has been tested only in Chrome.

Similar modules

If this doesn't look right for you*, check out some alternatives:

* As a sidenote, I'd appreciate you taking the time to let me know why

Licensing

  • SilverStripe CropperField is released under the BSD License; however, please note:
  • Cropper v0.7.5 is released under the MIT license.

Built by

Will Morgan, who is available for hire.

willmorgan/silverstripe-cropperfield 适用场景与选型建议

willmorgan/silverstripe-cropperfield 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 4.26k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2014 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「thumbnail」 「silverstripe」 「crop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 willmorgan/silverstripe-cropperfield 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 willmorgan/silverstripe-cropperfield 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 28
  • Watchers: 7
  • Forks: 5
  • 开发语言: JavaScript

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-12-10