简体   繁体   English

干预图像Laravel 5.1

[英]Intervention Image Laravel 5.1

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

Try: 尝试:

1) check if you have model in your App (by default) folder named as Image 1)检查您的应用程序(默认情况下)中是否有名为Image的模型

2) 2)

a) put use Image; a) use Image; to the top of your controller 到控制器的顶部

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(

I had the same problem myself. 我自己也有同样的问题。 After a lot of googling, I found this tutorial specific for Laravel 5.1. 经过大量的谷歌搜索,我发现本教程专门针对Laravel 5.1。

Simply change 简单地改变

use Intervention\Image\Image;

to

use Intervention\Image\Facades\Image;

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/

The simplest method is to use facade instead of provider. 最简单的方法是使用facade而不是provider。

So instead of: 所以代替:

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);

Open : config/app.php 打开:config / app.php

Add to array aliases : 添加到数组别名:

'Image' => Intervention\Image\ImageManagerStatic::class,

In Controller : 在控制器中:

use Image;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM