konnco / laravel-onimage
提升您的编码速度,无需再担心图像管理。
v2.x-dev
2020-10-27 05:48 UTC
Requires
- php: >=7.2.0
- illuminate/contracts: ^5.6|^6.0|^7.0|^8.0
- illuminate/database: ^5.6|^6.0|^7.0|^8.0
- illuminate/support: ^5.6|^6.0|^7.0|^8.0
- intervention/image: ^2.5
- intervention/imagecache: ^2.4
- ralouphie/mimey: ^2.1
Requires (Dev)
- orchestra/testbench: 3.8.* || ^4.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-07 09:54:07 UTC
README
此包旨在提高您在 Laravel 框架中管理图像的开发效率。
此包基于著名的 Intervention/Image
安装
composer require composer require konnco/laravel-onimage
php artisan vendor:publish
php artisan migrate
配置
您可以在 config/onimage.php
中找到 onimage 配置。
用法
将 onimage 特性添加到您的模型中
namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class News extends Model { use \Konnco\Onimage\Onimage; }
快速示例
上传图像
$news = News::find(1); $news->onImageSet('featured', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80'); // Or for new instance $news = new News; $news->title = "hello world"; $news->save(); $news->onImageSet('featured', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80'); // You can pass an array too $news->onImageSet('featured', [ 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80' ]);
多图
// Pushing into existing attribute $news = News::find(1); $news->onImagePush('featured', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80'); // You can insert it as an array too $news->onImagePush('featured', [ 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80', 'https://images.unsplash.com/photo-1562887250-9a52d844ad30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2089&q=80']);
检查属性是否存在
$news = News::find(1); $news->onImageHas('featured');
获取单个图像
$news = News::find(1); $news->onImageFirst('featured', 1);
获取图像集合
$news = News::find(1); $news->onImageGet('featured');
删除图像
$news = News::find(1); $news->onImageDelete('featured', 1); // Or delete batch $news->onImageDelete('featured', [1, 2, 3]);
上传类型
您可以将以下类型插入到 onimage 字段中
- string - 文件系统中图像的路径。
- string - 图像的 URL(必须启用 allow_url_fopen)。
- string - 二进制图像数据。
- string - 数据 URL 编码的图像数据。
- string - Base64 编码的图像数据。
- resource - 类型为 gd 的 PHP 资源。(使用 GD 驱动时)
- object - Imagick 实例(使用 Imagick 驱动时)
- object - Intervention\Image\Image 实例
- object - SplFileInfo 实例(处理 Laravel 文件上传通过 Symfony\Component\HttpFoundation\File\UploadedFile)
作者
贡献
我们感谢所有贡献,欢迎您编写代码或请求包。