drzippie/crop 问题修复 & 功能扩展

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

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

drzippie/crop

Composer 安装命令:

composer require drzippie/crop

包简介

Modern PHP library for intelligent image cropping with multiple algorithms

README 文档

README

CI Status PHPStan Level PHP Version License Latest Stable Version Total Downloads

This is a maintained fork of the original stojg/crop library, which was archived on April 30, 2021. This fork continues development and adds modern improvements.

Key enhancements in this fork:

  • ✅ Modern PHP 8.3+ compatibility with strict typing
  • ✅ Comprehensive test suite with PHPUnit 11+
  • ✅ PHPStan level 8 compliance for type safety
  • ✅ Modernized dependencies and compatibility
  • ✅ Active maintenance and bug fixes

This is a small set of image croppers for automated cropping with intelligent algorithms.

Requirements

  • PHP 8.3 or higher
  • ImageMagick extension with sRGB colorspace (version 6.7.5-5 or higher)

Description

This project includes three intelligent image cropping algorithms:

CropCenter

This is the most basic of cropping techniques:

  1. Find the exact center of the image
  2. Trim any edges that is bigger than the targetWidth and targetHeight

CropEntropy

This class finds the a position in the picture with the most "energy" in it. Energy (or entropy) in images are defined by 'edginess' in the image. For example a image of the sky have low edginess and an image of an anthill has very high edginess.

Energy is in this case calculated like this

  1. Take the image and turn it into black and white
  2. Run a edge filter so that we're left with only edges.
  3. Find a piece in the picture that has the highest entropy (i.e. most edges)
  4. Return coordinates that makes sure that this piece of the picture is not cropped 'away'

CropBalanced

Crop balanced is a variant of CropEntropy where I tried to the cropping a bit more balanced.

  1. Dividing the image into four equally squares
  2. Find the most energetic point per square
  3. Finding the images weighted mean interest point for all squares

Usage

Basic Usage

use drzippie\crop\{CropCenter, CropEntropy, CropBalanced};

// Center-based cropping (fastest)
$center = new CropCenter($filepath);
$croppedImage = $center->resizeAndCrop($width, $height);
$croppedImage->writeimage('assets/thumbs/cropped-center.jpg');

// Entropy-based cropping (intelligent edge detection)
$entropy = new CropEntropy($filepath);
$croppedImage = $entropy->resizeAndCrop($width, $height);
$croppedImage->writeimage('assets/thumbs/cropped-entropy.jpg');

// Balanced cropping (weighted center of interest)
$balanced = new CropBalanced($filepath);
$croppedImage = $balanced->resizeAndCrop($width, $height);
$croppedImage->writeimage('assets/thumbs/cropped-balanced.jpg');

Advanced Usage

use drzippie\crop\CropEntropy;

// Create cropper with custom settings
$crop = new CropEntropy();
$crop->setImage($imagickObject)
     ->setFilter(Imagick::FILTER_LANCZOS)
     ->setBlur(0.8)
     ->setAutoOrient(true);

$result = $crop->resizeAndCrop(300, 200);

Installation

Install via Composer:

composer require drzippie/crop

Documentation

📖 Complete Documentation - GitHub Pages with full API reference and examples

drzippie/crop 适用场景与选型建议

drzippie/crop 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 drzippie/crop 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2025-07-15