marshmallow/nova-advanced-image
Composer 安装命令:
composer require marshmallow/nova-advanced-image
包简介
An advanced image field for Nova with crop and resize.
关键字:
README 文档
README
Nova Advanced Image Field
An advanced image field for Nova with crop and resize.
This package provides an advanced image field for Nova resources allowing you to upload, crop and resize any image. It uses Cropper.js with vue-cropperjs in the frontend and Intervention Image in the backend.
Requirements
- PHP
^8.0 - Laravel Nova
^4.0or^5.0 - Intervention Image
^3.6
Intervention Image requires one of the following libraries for image processing:
- GD Library >=2.0 (used by default)
- Imagick PHP extension >=6.5.7
See the Intervention requirements for more details. The autoOrientate() helper additionally requires the PHP exif extension to be enabled.
Installation
Install the package into a Laravel application with Nova using Composer:
composer require marshmallow/nova-advanced-image
The field service provider is auto-discovered, so there is nothing further to register.
If you want to use Imagick as the default image processing library, follow the Intervention documentation for Laravel. This will provide you with a new configuration file where you can specify the driver you want. You can also override the driver per field with ->driver('imagick').
Usage
AdvancedImage extends Nova's Image field, so you can use any method that Image/File implements. See the Nova file field documentation for the inherited options.
<?php namespace App\Nova; // ... use Marshmallow\AdvancedImage\AdvancedImage; class Post extends Resource { // ... public function fields(Request $request) { return [ // ... // Simple image upload AdvancedImage::make('photo'), // Show a cropbox with a free ratio AdvancedImage::make('photo')->croppable(), // Show a cropbox with a fixed ratio AdvancedImage::make('photo')->croppable(16 / 9), // Resize the image to a max width AdvancedImage::make('photo')->resize(1920), // Resize the image to a max height AdvancedImage::make('photo')->resize(null, 1080), // Show a cropbox and resize the image AdvancedImage::make('photo')->croppable()->resize(400, 300), // Auto-rotate based on the image's Exif orientation (requires the exif extension) AdvancedImage::make('photo')->autoOrientate(), // Override the image processing driver for this field only ('gd' or 'imagick') AdvancedImage::make('photo')->driver('imagick')->croppable(), // Store to AWS S3 AdvancedImage::make('photo')->disk('s3'), // Specify a custom subdirectory AdvancedImage::make('photo')->disk('s3')->path('image'), ]; } }
The resize option uses Intervention Image resize() with the upsize and aspect ratio constraints.
Available methods
| Method | Description |
|---|---|
croppable($param = true) |
Enable the crop box. Pass a numeric value (e.g. 16 / 9) to lock a fixed aspect ratio. |
resize($width = null, $height = null) |
Resize the stored image to a maximum width and/or height. |
driver(string $driver) |
Override the Intervention driver for this field. Accepts gd or imagick. |
autoOrientate() |
Rotate the image to the orientation stored in its Exif data. Requires the PHP exif extension. |
customThumbnail($callable) |
Customise the thumbnail URL resolver (proxies Nova's thumbnail()). |
customPreview($callable) |
Customise the preview URL resolver (proxies Nova's preview()). |
setCustomCallback($customCallback) |
Run a custom callback after the image has been stored. |
Avatar variant
For avatar-style fields, use AdvancedAvatar. It extends AdvancedImage, implements Nova's Cover contract and renders a rounded thumbnail.
use Marshmallow\AdvancedImage\AdvancedAvatar; AdvancedAvatar::make('avatar')->croppable(1),
Security
If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.
Changelog
Please see CHANGELOG for recent changes.
Credits
- Marshmallow
- Clément Tessier (original author)
- All Contributors
License
The MIT License (MIT). Please see the License File for more information.
marshmallow/nova-advanced-image 适用场景与选型建议
marshmallow/nova-advanced-image 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 65.48k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「nova」 「resize」 「image resize」 「laravel」 「crop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marshmallow/nova-advanced-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marshmallow/nova-advanced-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marshmallow/nova-advanced-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
统计信息
- 总下载量: 65.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 22
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-17
