smallunit / image
图像调整大小:高度、宽度和质量
This package is not auto-updated.
Last update: 2024-09-26 02:52:59 UTC
README
小单元可以在许多应用程序中使用,其一个目的是调整图像大小。添加这个非常快速的单元,因为它在任何服务提供商上都能工作,并且非常特别的是,它不会在自动加载中占用时间。
贡献
感谢您考虑为 smallUnit 组件做出贡献!贡献指南可以在 Laravel 文档 中找到。
安全漏洞
如果您在 smallUnit 中发现安全漏洞,请发送电子邮件至 Taylor Otwell(abdo.gamy2010@gmail.com)。所有安全漏洞都将得到及时处理。
许可
smallunit 框架是开源软件,遵循 MIT 许可。##文档###首先使用 composer 下载...
composer require smallunit/image
###然后,通过在 laravel 中使用任何活动的服务提供商绑定类,如 app/Providers/AppServiceProvider.php 路径是由 laravel 复制的
$this->app->bind("image", function () {
return new Image(config('config_file_name.versions'));
});
在 AppServiceProvider@boot 方法中。[config_file_name] 你可以在任何文件中配置你的版本,或者在你自己的配置文件中创建一个配置文件,在 [project_name/config/myconfigFile],[versions] 是数组版本的关键,你可以更改它。###最终在 config/app.php 中添加 Facade 别名
'Image'=> Image\Facades\Image::class,
###配置添加到你定义的文件中的服务提供者,结构如下
|--------------------------------------------------------------------------
| Image versions
|--------------------------------------------------------------------------
| Defining your standard versions 's information for image which you
| resize. it is very easy way and very simple code to resize image
*/
'versions' => [
'Profile'=>[// version name
'height'=>'150',
'width'=>'200',
'quality'=>'100',//quality of new version
'suffix'=>'profile',//suffix of version
'path'=>''//form public path in laravel project
],
//another version
'Icons-posts'=>[
'height'=>'75',
'width'=>'75',
'quality'=>'50',
'suffix'=>'icons',
'path'=>'src/img/posts/'
]
],
##函数
/**
* add runtime versions
* @param $version
*/
Image::addVersion($versionArray)
/**
* Make all version for image
* @param $originalPath > the path of originalPath
*/
Image::makeAllVersions($originalPath)
/**
* Make version which his name $versionName
* @param $versionName
* @param $originalPath
*/
Image::makeVersion($versionName, $originalPath)
**
* @param $versionName
* @param $originalPath
* @return string path of the version will be created or been created
*/
Image::getVersionPath($versionName, $originalPath)
/**
* return the suffix of version
* @param $versionName
* @return mixed
*/
Image::suffix($versionName)
##示例应用此文档
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Image\Image;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app->bind("image", function () {
return new Image(config('services.versions'));//Enter the you config_file , version
});
}
......................................
然后...
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
..
...
...
...
.....
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\UR
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Image'=> Image\Facades\Image::class,
],
在 config/services.php 中添加版本,如下所示
|--------------------------------------------------------------------------
| Image versions
|--------------------------------------------------------------------------
| Defining your standard versions 's information for image which you
| resize. it is very easy way and very simple code to resize image
*/
'versions' => [
'Profile'=>[// version name
'height'=>'150',
'width'=>'200',
'quality'=>'100',//quality of new version
'suffix'=>'profile',//suffix of version
'path'=>''//form public path in laravel project
],
//another version
'Icons-posts'=>[
'height'=>'75',
'width'=>'75',
'quality'=>'50',
'suffix'=>'icons',
'path'=>'src/img/posts/'
]
],
路由调整测试...
Route::get('reszie',function(){
//Add path the original path
Image::makeAllVersions(public_path('src/1825537641364050182.jpg'));
return 'done';
});
要获取版本路径,请使用 [getVersionPath] 方法。发送您的反馈 abdo.gamy2010@gmail.com