Laravel image resize ( resmi yeniden boyutlandırma)
Laravelde resim kırpma resim boyutlandırma işlemini çok basit bir şekilde gerçekleştirebiliriz.Bunun için intervention dan yararlanıcaz.Peki nasıl yapabiliriz ?
Composer ile kütüphaneimizi indirelim
1 |
composer require intervention/image |
daha sonra config/app.php açıp $providers dizimize providerımızı ekleyelim
1 |
Intervention\Image\ImageServiceProvider::class |
daha sonra $aliases dizimize Facademızı ekleyelim
1 |
'Image' => Intervention\Image\Facades\Image::class |
Cmd den
1 |
php artisan storage:link |
komutunu çalıstıralım
kurulumumuz tamamlandı.artık controllerımızın içersine en üste
1 |
use Image; |
dahil ederek kullanabiliriz
1 2 3 4 5 6 7 8 |
<form action="{{ url('PASS_ACTION_URL') }}" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="exampleInputFile">File input</label> <input type="file" name="profile_image" id="exampleInputFile"> </div> {{ csrf_field() }} <button type="submit" class="btn btn-default">Yükle</button> </form> |
Controller dosyamız
1 2 3 4 5 6 7 8 9 10 11 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Image; class ImageController extends Controller { } |
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 |
public function yukle(Request $request) { if($request->hasFile('profile_image')) { $filenamewithextension = $request->file('profile_image')->getClientOriginalName(); $filename = pathinfo($filenamewithextension, PATHINFO_FILENAME); $extension = $request->file('profile_image')->getClientOriginalExtension(); $filenametostore = $filename.'_'.time().'.'.$extension; //Upload File $request->file('profile_image')->storeAs('public/profile_images', $filenametostore); $request->file('profile_image')->storeAs('public/profile_images/thumbnail', $filenametostore); //Resize image $thumbnailpath = public_path('storage/profile_images/thumbnail/'.$filenametostore); $img = Image::make($thumbnailpath)->resize(400, 150, function($constraint) { $constraint->aspectRatio(); }); $img->save($thumbnailpath); return redirect('images')->with('success', "Image uploaded successfully."); } } |
Takıldığınız yer olursa yardımcı olurum.Bol kodlu günler
Etiketler: laravel, laravel dersleri, laravel image resize, laravel resim boyutlandırma, laravel resim kırpma, php, php resim boyutlandırma, php resim kırpma