Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am working on a marketing website with laravel 5.4 i need to upload and load lots of images on the website, if i load the original image every time, it will going slow. so i need your suggestions *

  1. should i store the image with two quality? (original and resized)
  2. store the original images, resize them when they loaded on the screen? (need an API)

share some ideas and the solutions please! if you have such an API, please share!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
166 views
Welcome To Ask or Share your Answers For Others

1 Answer

Laravel does not have a default resize of image. But most laravel developers use 'Image intervention' in handling the image. (Easy to use)

To install (Image intervention):

STEP 1 Run

 composer require intervention/image

STEP 2 On your config/app.php:

In the $providers array, add the following:

  InterventionImageImageServiceProvider::class

In the $aliases array,add the following:

 'Image' => InterventionImageFacadesImage::class

If you have problems your GD librabry is missing, intall it

 PHP5: sudo apt-get install php5-gd
 PHP7: sudo apt-get install php7.0-gd

~~ To use on your controller ~~

STEP 3 On top of your controller

use InterventionImageImageManagerStatic as Image;

STEP 4 On your method (there are several ways but this will give you an idea)

 if($request->hasFile('image')) {

   $image       = $request->file('image');
   $filename    = $image->getClientOriginalName();

   $image_resize = Image::make($image->getRealPath());              
   $image_resize->resize(300, 300);
   $image_resize->save(public_path('images/ServiceImages/' 
  .$filename));

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...