restruct/silverstripe-focuspointcropper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

restruct/silverstripe-focuspointcropper

Composer 安装命令:

composer require restruct/silverstripe-focuspointcropper

包简介

Even smarter automatic image cropping for SilverStripe

README 文档

README

This module adds a visual crop interface to Silverstripe's AssetAdmin, building on top of jonom/focuspoint. It allows editors to define an initial crop region that serves as the basis for FocusPoint's intelligent cropping.

Crop interface in AssetAdmin

Set crop & zoom level (drag/scroll) and FocusPoint (click) directly in the CMS.

Image by Nikolay Nachev (Pixabay)

Version Compatibility

Branch Module Version Silverstripe FocusPoint PHP
master 2.x ^4.0 || ^5.0 ^4.0 || ^5.0 ^7.4 || ^8.0

Note: composer.json is the source of truth for exact version constraints. This module replaces the older micschk/silverstripe-focuspointcropper package. Silverstripe 6 support is planned.

Basic Usage

When you edit an image in the CMS (AssetAdmin), an extra "Focus Point + Crop" field appears:

  1. Scroll on the image to zoom in/out
  2. Drag the image to pan and position the crop area
  3. Click on the subject of the image to set the focus point
  4. Save the image to apply the crop data

The crop data is stored on the image and used as the basis for all subsequent manipulations.

How It Works

CropData Storage

When you define a crop region in the CMS, the module stores CropData as JSON on the Image record. This contains:

  • Crop region coordinates (x, y, width, height)
  • Zoom level
  • Canvas dimensions

Image Manipulation Methods

The module adds several manipulation methods to Image:

Cropped Methods - Apply CropData before standard manipulation:

  • CroppedImage($width, $height) - Apply crop, then resize to fit
  • CroppedFill($width, $height) - Apply crop, then fill exact dimensions
  • CroppedFocusFill($width, $height) - Apply crop, then focus-aware fill

Focus-Aware Cropped Methods - Combine CropData with FocusPoint:

  • CroppedFocusFill($width, $height) - Uses both CropData and FocusPoint for optimal results
  • CroppedFocusCropWidth($width) - Crop to width, respecting both crop region and focus point
  • CroppedFocusCropHeight($height) - Crop to height, respecting both crop region and focus point

SVG Support

When used together with restruct/silverstripe-svg-images, all crop methods work seamlessly with SVG files. The svg-images module automatically detects when this module is installed and enables crop support for SVGs.

Template Usage

<!-- Standard manipulation (uses CropData if set) -->
<img src="$Image.CroppedFill(400, 300).URL" alt="$Image.Title">

<!-- Focus-aware cropping (uses both CropData and FocusPoint) -->
<img src="$Image.CroppedFocusFill(400, 300).URL" alt="$Image.Title">

<!-- Fallback for images without CropData -->
<img src="$Image.Fill(400, 300).URL" alt="$Image.Title">

Development Tools

Crop Functionality Test Page

A visual comparison tool is available at /dev/crop-compare to test crop functionality with both SVG and PNG images.

Crop Compare Test Tool

The tool:

  • Tests all Cropped* methods (CroppedImage, CroppedFill, CroppedFocusFill, etc.)
  • Compares regular manipulations with Cropped* versions
  • Shows badges indicating which methods use CropData and/or FocusPoint
  • Includes bundled test images with pre-configured CropData and FocusPoint
  • Works with custom image IDs for testing your own images

Test Image Features:

  • Dashed lines mark the crop boundaries
  • White crosshair marks the FocusPoint location
  • Orange triangle is near the FocusPoint - should stay visible in FocusFill crops
  • Red circle is left of center - may be cropped in narrow FocusFill

Configuration

Configuration options can be set using Silverstripe's Config API:

# Cropper field configuration
Restruct\SilverStripe\ImageCropper\FocusPointCropField:
  cropconfig:
    aspectRatio: 1.777  # 16:9 ratio
    autoCropArea: 0.8   # Initial crop covers 80% of image

For all available cropper options, see Cropper.js documentation.

Related Modules

License

BSD-3-Clause

restruct/silverstripe-focuspointcropper 适用场景与选型建议

restruct/silverstripe-focuspointcropper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 650 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-06-16