c2h6/twill-croppa
Composer 安装命令:
composer require c2h6/twill-croppa
包简介
Use Croppa as media rendering service in Twill applications
README 文档
README
Use Croppa as media rendering service in Twill applications.
Learn more about Croppa at https://github.com/BKWLD/croppa
Learn more about Twill CMS at https://twillcms.com
About this package
This package provides an easy-to-use integration of the Croppa image library into Twill CMS to use as a media and image rendering service. When switching to the provided rendering service, the advantages of Croppa can be used in your Twill application. In addition, a few other utils for working with media in the context of Twill are offered.
Features
- image rendering service for interfacing with the twill media library
- easy configuration of all plugin settings
- some croppa preconfiguration
- automatic crops deletion on media removal
- traits for media detaching on model deletion
Prequesites/Versioning
Use the following table to find the right version for your Laravel/Twill/Croppa version to fit your environment.
All package releases are available via GitHub and Packagist releases to download.
| Package version | Croppa version | Twill version | Laravel version |
|---|---|---|---|
| 1.x | 6.x | 3.x | 10.x |
| 2.x | 6.x (Patched)* | 3.4 | 11.x |
| 3.x (Current Version) | 6.x (Patched)* | 3.5/dev | 12.x |
Warning
V3 depends on a forked version of BKWLD/croppa with applied patches to function with Laravel 12 and the newest version of Twill. Twill depends on older versions of packages used by Croppa, resulting in dependency configurations not installable by composer.
The Fork and more information is available at https://github.com/C2H6-383/croppa. As soon, as these dependency conflicts are resolved, twill-croppa will get an update to use the original version of Croppa once more.
Requirements
This package requires the Composer PHP package manager to function and manage its dependencies.
In addition, this package only depends on Twill CMS and Croppa and their dependencies. This is automatically managed via Composer.
Installation
Installation of this library is easy to do via Composer:
composer require c2h6/twill-croppa
Important
To use this package in your Laravel project with the patched version of Croppa, you need to add the vsc repository for the patched Croppa version to your root composer-file by adding:
"repositories": [ { "type": "vcs", "url": "https://github.com/C2H6-383/croppa-twill-compatible" } ],
Please run composer u to update your packages after that.
If you do not need the patched version of Croppa, please use version 1.x of this package.
Package discovery is automatically done by the Laravel Framework.
You should already set up the storage linking for storing your media files. For further information check the Twill CMS Docs.
Usage
Using the Croppa rendering service is really easy. Just set the rendering service config property in the Twill configuration. Everything else is set up for you.
To set the Image Rendering Service edit the media_library.image_service property in the twill.php config file. You maybe need to publish the Twill config files first or add the config properties.
... 'media_library' => [ 'image_service' => \C2H6\TwillCroppa\TwillCroppa::class, ], ...
For more additional help see https://twillcms.com/docs/media-library/image-rendering-service.html
A note on performance
When accessing crops for the first time, Croppa needs to render each image. On some servers or environment configurations, this is really slow (2+ seconds per image request). This gets exponentially worse when having many crops or images per page, as these are rendered on-demand.
To hide this from normal visitors when accessing the page, it is recommended to view the preview or access the page before publishing and waiting for all images to load in. An alternative is to render the crops programmatically (see the Croppa documentation section about the render command) beforehand or via a queue job.
To use the LQIP images, use the command php artisan twill:lqip to generate and store them in the database.
Configuration Options
If you want to change configuration options of this plugin, you can either create a new configuration file called twillcroppa.php in the Laravel config directory or publish the default configuration file with the command php artisan vendor:publish --tag=twillcroppa-config. A list with a detailed description of the configuration options is displayed below.
This library automatically configures some croppa parameters. To further refine the Croppa settings, please refer to the configuration options of Croppa stated in the Croppa documentation.
| config option | Default | description |
|---|---|---|
| lqip_dimension | 30 | Default image width/height of the LQIP image if dimensions are not provided. |
| lqip_quality | 25 | JPEG quality (0-100) for the LQIP images, higher means better image quality but larger files |
| media_files_path | storage/uploads/ |
uploads storage path (URL) for discovering and deleting crops |
Extra: Media Detaching on Model deletion
When dealing with media models while working with Twill there is often the burden to detach any media when deleting a model. Otherwise, there are some dangling references remaining and any of these media files can never be deleted from the application, as twill registers some usage cases.
To speed this process up, this package contains a few PHP traits to automatically detach any media relations on deleting or force deleting a given model:
C2H6\TwillCroppa\Traits\DetachMediaOnForceDelete::class for automatically deleting relations on model force deletion and
C2H6\TwillCroppa\Traits\DetachMediaOnDelete::class for automatically deleting relations on model (soft) deletion.
For normal use cases, only the first one should be needed, as Twill always uses soft deletes per default. On model deletion, the model is put in a Trash section, where a recovery is possible. Only on removal from this Trash section, a media detachment should be done.
Usage
To use these traits just add them to any of your models and they should work out of the box.
Package Development
- clone or fork this GitHub repository and download it to your dev environment
- install all composer dependencies with
composer install - run tests with the command
composer test - just submit issues and pull requests
c2h6/twill-croppa 适用场景与选型建议
c2h6/twill-croppa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 850 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「media」 「image」 「laravel」 「twill」 「croppa」 「twillcms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 c2h6/twill-croppa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 c2h6/twill-croppa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 c2h6/twill-croppa 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
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.
Laravel Media Popup to upload/view the files
Asset Manager Laravel package for Gigcodes UI Library
统计信息
- 总下载量: 850
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-23