干预图像 Laravel 5.1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31501659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Intervention Image Laravel 5.1
提问by Jensej
I tried to resize img, I do this step: update composer:
我尝试调整 img 的大小,我执行以下步骤:更新作曲家:
"intervention/image": "dev-master",
next add lines in app/config
接下来在 app/config 中添加行
Intervention\Image\ImageServiceProvider::class,
'Image' => Intervention\Image\Facades\Image::class
In my controller:
在我的控制器中:
use Intervention\Image\Image as Img;
Img::make($destination_path . $filename)->resize(200, 200)->save($destination_path . $filename);
and this is error:
这是错误:
Call to undefined method Intervention\Image\Image::make()
All In laravel 5.1
全部在 Laravel 5.1
采纳答案by M0rtiis
Try:
尝试:
1) check if you have model in your App (by default) folder named as Image
1)检查您的应用程序(默认情况下)文件夹中是否有名为 Image 的模型
2)
2)
a) put use Image;
to the top of your controller
a) 放在use Image;
控制器的顶部
b) throw this away: use Intervention\Image\Image as Img;
b) 扔掉它:使用 Intervention\Image\Image 作为 Img;
c) just use this: Image::make(
not Img:make(
c) 只使用这个:Image::make(
不是 Img:make(
回答by miniPax
I had the same problem myself. After a lot of googling, I found this tutorialspecific for Laravel 5.1.
我自己也有同样的问题。经过大量的谷歌搜索,我发现本教程专门针对 Laravel 5.1。
Simply change
简单地改变
use Intervention\Image\Image;
to
到
use Intervention\Image\Facades\Image;
回答by Mamun Rasid
Just follow the below Steps:
只需按照以下步骤操作:
1) Open composer.json file from your root directory
1) 从你的根目录打开 composer.json 文件
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravel/socialite": "^2.0",
// add these lines
"illuminate/html": "5.*",
"intervention/image": "dev-master"
}
2) Now run composer update command to get those packages.
2) 现在运行 composer update 命令来获取这些包。
composer update
3) Open config/app.php file
3) 打开 config/app.php 文件
a) update the providers array with the following line.
a) 使用以下行更新 providers 数组。
'providers' => [
// add this line at the bottom
Intervention\Image\ImageServiceProvider::class
]
b) update the aliases array with the following line.
b) 使用以下行更新别名数组。
'aliases' => [
// add this line at the bottom
'Image' => Intervention\Image\Facades\Image::class
],
4) You are done!
4)你完成了!
See details here: http://www.pranms.com/intervention-image-integration-in-laravel/
在此处查看详细信息:http: //www.pranms.com/intervention-image-integration-in-laravel/
回答by Kornel
The simplest method is to use facade instead of provider.
So instead of:
最简单的方法是使用 Facade 而不是 provider。
所以而不是:
use Intervention\Image\Image as Img;
just put this:
只是把这个:
use Image;
And then you can use it like this:
然后你可以像这样使用它:
Image::make($destination_path . $filename)->resize(200, 200)->save($destination_path . $filename);
回答by Thành Nguy?n
Open : config/app.php
打开:config/app.php
Add to array aliases :
添加到数组别名:
'Image' => Intervention\Image\ImageManagerStatic::class,
In Controller :
在控制器中:
use Image;