| Yêu cầuĐể tối ưu ảnh khi hiển thị trên nhiều thiết bị khác nhau. Khi người dùng upload 1 hình ảnh bất kỳ. Thông thường chúng ta sẽ:
 	Ví dụ: người dùng upload file ảnhTự động sinh ra nhiều file ảnh bằng cách điều chỉnh kích cỡ (resize ảnh).Được đặt tên theo quy cách ten_file_anh_rong_x_cao hoa-hong.jpg, có kích thước thực của file ảnh là 3200x1900 px. Chúng ta sẽ tự sinh ra các file như sau:
 	hoa-hong.jpghoa-hong-100x100.jpghoa-hong-150x150.jpghoa-hong-300x169.jpghoa-hong-450x450.jpghoa-hong-600x338.jpghoa-hong-768x432.jpghoa-hong-1024x576.jpg... Các bước thực hiệnĐể thuận tiện chúng ta sẽ sử dụng thư viện hiệu chỉnh ảnh nổi tiếng của PHP là https://github.com/Intervention/imageStep 1: cài đặt thư việnGõ câu lệnh vào cmd:composer require intervention/image Step 2: bật cấu hình sử dụng thư viện Intervention ImageHiệu chỉnh fileconfig/app.phpreturn [
    ......
    ......
    $provides => [
        ......,
        Intervention\Image\ImageServiceProvider::class
    ],
    $aliases => [
        .....,
        'Image' => Intervention\Image\Facades\Image::class
    ]
]Step 3: bổ sung bước xử lý lưu ảnh theo tỷ lệ mong muốn trong Action của Controller thích hợp/**
     * Image resize
     */
    public function imgResize(Request $request)
    {
 
        $image = $request->file('imgFile');
        $input['imagename'] = time().'.'.$image->extension();
     
        $filePath = public_path('/thumbnails');
        $img = Image::make($image->path());
        $img->resize(110, 110, function ($const) {
            $const->aspectRatio();
        })->save($filePath.'/'.$input['imagename']);
   
        $filePath = public_path('/images');
        $image->move($filePath, $input['imagename']);
   
        return back()
            ->with('success','Image uploaded')
            ->with('fileName',$input['imagename']);
    } |