lifeentity / images
此包的最新版本(dev-master)没有可用的许可信息。
dev-master
2014-09-27 22:51 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.2.*
- intervention/image: 2.*
This package is not auto-updated.
Last update: 2024-09-28 15:28:56 UTC
README
这个 Laravel 4 包提供了一种简单的方法,可以在运行时生成和缓存图像。
安装
首先,通过 Composer 安装此包。编辑你的项目 composer.json
文件,添加 lifeentity/images
作为依赖项。
"require": {
"lifeentity/images": "2.*"
}
接下来,在终端中更新 Composer
composer update
一旦此操作完成,最后一步是添加服务提供者。打开 app/config/app.php
文件,并将新的项目添加到 providers 数组中。
'Lifeentity\Images\ImagesServiceProvider'
接下来,运行此迁移命令以创建图像表(不要忘记配置你的数据库)
php artisan migrate --package=lifeentity/images
可选步骤,运行此 artisan 命令以发布配置文件
php artisan config:publish lifeentity/images
配置文件包含有关
- 你的图像目录
- 基本路径
- 缓存目录名称
用法
将任何你的模型附加到图像 eloquent 模型。
<?php use Lifeentity\Images\ImageDB; class Product { // ... protected function images() { return $this->morphMany('Lifeentity\Images\ImageDB', 'imageable'); } }
创建新图像并将其保存到产品中
<?php // Create a new image and attach it to a product $image = new ImageDB(array( 'path' => '/images/path/to/image/image.jpg' )); Product::find(1)->image()->save($image);
显示产品原始图像和图像的缩略版本
<?php $image = Product::find(1); echo '<img src="'.$image->original_url.'" />'; // Resize image before displaying to the user echo '<img src="'.$image->addOperation('resize', 300, null, true)->cached_url.'" />';
想要对图像进行复杂操作?注册一个图像过滤器
<?php // Register new operation App::make('Lifeentity\Images\ImageFilter')->register('watermark.v1', function(Intervention\Image\Image $image) { // If you want you can add this facade to the aliases in the app.php config file $watermark = \Intervention\Image\Facades\Image::make(public_path('/images/watermark.jpg')); // For a list of operations you can do on an image please refer to intervention image package bellow $watermark->resize(0.4 * $image->getWidth(), null, function($constraints) { $constraints->aspectRatio(); }); $image->insert($watermark, 'bottom-right'); });
此包依赖于 intervention/image v2.*。关于您可以在图像上执行的操作的列表,请参阅此链接 Intervention Image