intervention/image intervention/imagecache

时间:2021-09-19 06:10:30

http://image.intervention.io/

安装两个包

composer require intervention/image

composer require intervention/imagecache

使用

$img = Image::make('public/foo.jpg')->resize(, )->insert('public/watermark.png')->save('public/bar.jpg');
// resizing an uploaded file
Image::make(Input::file('photo'))->resize(300, 200)->save('foo.jpg');

Creating Image from File Upload

// read image from temporary file
$img = Image::make($_FILES['image']['tmp_name']); // resize image
$img->fit(, ); // save image
$img->save('foo/bar.jpg');

laravel router

Route::get('/image/{path}', function($path){
    $img = Image::cache(function($img) use($path) {
                   $img->make(public_path().'/'.$path)->resize(300, 200);
            }, 10, true);
    return $img->response('jpg');
})->where(['path' => '[0-9a-z\/\._]+']);