ayvazyan10/nova-imagic
Composer 安装命令:
composer require ayvazyan10/nova-imagic
包简介
Imagic is a Laravel Nova field package that allows for image manipulation capabilities, such as cropping, resizing, quality adjustment, and WebP conversion. It utilizes the powerful Intervention Image class for image manipulation.
README 文档
README
Imagic is a Laravel Nova field package that allows for image manipulation capabilities, such as cropping, resizing, quality adjustment, and WebP conversion. It utilizes the powerful Intervention Image class for image manipulation. The purpose of this package is to optimize images for web usage by converting them to the WebP format, which provides superior compression and faster load times.
Advanced Image Manipulation Made Easy with Images Magic
✅ Single/Multiple Uploads
✅ Cropping
✅ Resizing
✅ Fitting
✅ Quality Control
✅ WebP Conversion
✅ Watermarking
✅ Custom Directories
Requirements
- PHP (^7.1 or higher)
- Laravel Nova (^4.0 or higher)
🚀 Installation
Install the package via Composer.
composer require ayvazyan10/nova-imagic
📚 Usage
Here is an example of how to use Imagic in your Laravel Nova application: In your Laravel Nova resources, use the Imagic field:
use Ayvazyan10\Imagic\Imagic; public function fields(Request $request) { return [ // ... Imagic::make('Image', 'image'), // ... ]; }
⚡ All Methods
Imagic::make('Image') ->multiple() ->crop($width, $height, $left = 0, $top = 0) ->resize($width, $height) ->fit($width, $height) ->widen($width) ->quality($quality) ->disk($path) ->directory($path) ->convert($convert = true) ->watermark($path, $position = 'bottom-right', $x = 0, $y = 0);
📖 Examples
Below are some examples in different scenarios.
- Multiple Images
To enable multiple image uploads, use the multiple() method. Note that when you use the multiple() method, your database column should be of type text, longtext, or json to store all images in a JSON format. Additionally, you will have the ability to sort uploaded images by drag and drop.
Imagic::make('Images')->multiple(),
- Cropping
To crop images, use the crop() method:
- x (optional) X-Coordinate of the top-left corner if the rectangular cutout. By default the rectangular part will be centered on the current image.
- y (optional) Y-Coordinate of the top-left corner if the rectangular cutout. By default the rectangular part will be centered on the current image.
Imagic::make('Image')->crop($width, $height, $x, $y),
- Resizing
To resize images, use the resize() method:
Imagic::make('Image')->resize($width = int|null, $height = int|null),
- Widen resizing by width
Specify the desired (only - width) for image resizing.
- The height will be automatically adjusted to maintain the aspect ratio.
Imagic::make('Image')->widen($width = int),
- Quality
To adjust the image quality, use the quality() method: default is 90
Imagic::make('Image')->quality(90),
- WebP Conversion
To convert images to WebP format, use the convert() method:
By default, the images will be converted to WebP format. To disable conversion, pass false to the convert() method:
Imagic::make('Image')->convert(false),
- Fit
You can use the fit() method when defining the Imagic field in your Nova resource:
Imagic::make('Image')->fit($width, $height),
- Field with watermark
Replace the /path/to/watermark.png with the actual path to your watermark image.
This will add the watermark to the image with the specified path, position, and offset (15x15 pixels from the bottom-right corner in this example).
Remember to import the Imagic class at the top of your Nova resource file:
Imagic::make('Image')->watermark('/path/to/watermark.png', 'bottom-right', 15, 15),
- Specified disk
Here is an example of how to use it:
Imagic::make('Image')->disk('public')
Caution: The disk is not working with custom directories and will throw an error.
- Directory Customization
BY DEFAULT - Imagic uses this structure: /storage/imagic/year/month/day/image_name.webp
The Imagic class includes a directory() method that allows you to specify a custom directory path for your image uploads. This allows for more flexibility in managing the location of your image files.
To use this feature, call the directory() method when creating an Imagic field and provide it with your custom directory path as an argument. This path should be a string, and should not start or end with a /.
Here is an example of how to use it:
Imagic::make('Image')->directory('your/custom/directory')
In this example, any images uploaded through this field will be saved in your/custom/directory.
Caution: The provided directory path should not start or end with a /. If it does, an InvalidArgumentException will be thrown. Make sure your directory path is correctly formatted when using this feature.
For example, the following code would throw an exception:
// This will throw an exception because the directory path starts with a '/' // Directory structure should not start or end with a slash. Only in the middle. Imagic::make('Image') ->directory('/invalid/directory/path')
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email ayvazyan403@gmail.com instead of using the issue tracker.
Author
License
MIT. Please see the license file for more information.
ayvazyan10/nova-imagic 适用场景与选型建议
ayvazyan10/nova-imagic 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 4.48k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2023 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「images」 「nova」 「resize」 「image resize」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ayvazyan10/nova-imagic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ayvazyan10/nova-imagic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ayvazyan10/nova-imagic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
A Laravel Nova package for publishable fields
统计信息
- 总下载量: 4.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-02