Official Site:
http://image.intervention.io/getting_started/installation
composer require intervention/image
Resize and Crop Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
private function save_s3($path){ if(is_s3($path) == true){ return true; } //Relative path -> full path $file_path = public_path($path); $file = File::get($file_path); //logg($path); $result = Storage::disk('s3')->put($path, $file, 'public'); //Handle thumb $dir = dirname($file_path) . '/thumbs/'; if(file_exists($dir) == false){ mkdir($dir); } $file_name = basename($file_path); $thumb = $dir . $file_name; if(file_exists($thumb) == false){ //Make a new thumb file $image = Image::make($file_path); $width = $image->width(); $height = $image->height(); if($width >= $height){ $image->resize(null, 150, function($constraint){ $constraint->aspectRatio(); }); }else{ $image->resize(150, null, function($constraint){ $constraint->aspectRatio(); }); } $image->crop(150, 150)->save($thumb); } $file = File::get($thumb); $path = dirname($path) . '/thumbs/' . $file_name; $result = Storage::disk('s3')->put($path, $file, 'public'); //logg($thumb); if($result != true){ return false; }else{ return true; } } |