Skip to main content

resize image and store it as thumbnail as well as store real image in laravel + resize image and store in laravel

Reference site 1: https://itsolutionstuff.com/post/laravel-5-image-upload-and-resize-example-using-intervention-image-packageexample.html

i.e.  intervention/image  in laravel

Main reference site is :
http://image.intervention.io/


when any error ocurs during integration then follow :


https://laracasts.com/discuss/channels/laravel/some-problems-with-install-intervention-image?page=1



INSIDE CONTROLLER :



use Intervention\Image\Facades\Image;


 In store funtion and update function:


if(!empty($request->file('image'))){
$file =$request->file('image');
// dd($file);
$path=base_path().'/public/multimedia_upload';
$thumbpath=public_path('/multimedia_upload');
// this above is folder name inside public folder where we store thubnail
$img = Image::make($file->getRealPath())->resize(100, 100,
function ($constraint) {$constraint->aspectRatio();});
$name=uniqid().'_'.$file->getClientOriginalName();
$thumbname=uniqid().'_'.$file->getClientOriginalName();
if($file->move($path,$name)){
$image=$name;
$input['image']=$image;
}
if($img->save($thumbpath.'/'.$thumbname))
//above code is to store image inside folder created above along with the name created above
{
$thumbimage=$thumbname;
$input['other_file']=$thumbimage;
}
}




Lets see next way to store image after resizing in laravel:


Reference :

https://stackoverflow.com/questions/40358510/resize-image-in-laravel-5-2?fbclid=IwAR3bO_etiRph2qrh4LaTCvPKMLGJWJ3W0pQkJU3Q-13tJw8bG7ZEqPhtynM

here , we use Intervention package to do so,

composer require intervention/image


STEP 2 On your config/app.php:
In the $providers array, add the following:
Intervention\Image\ImageServiceProvider::class
In the $aliases array,add the following:
'Image' => Intervention\Image\Facades\Image::class
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLantervention\Image\ImageServiceProviderLaravel5"
STEP 3 On top of your controller
use Intervention\Image\ImageManagerStatic as Image;
STEP 4 On your method (there are several ways but this will give you an idea)
 public function store(Request $request)
    
        {
            $input=$request->all();
    
            $image='';
            if(!empty($request->file('image'))){
                $file =$request->file('image');
                $path=base_path().'/public/success_upload/';
                $name=uniqid().'_'.$file->getClientOriginalName();
                $image_resize = Image::make($file->getRealPath());              
                $image_resize->resize(300, 300);
                if($image_resize->save($path.$name)){
                    $image=$name;
                    $input['image']=$image;
                }
use Intervention\Image\Facades\Image;
This is approved one i have done 
$image = '';
if (!empty($request->file('image'))) {
$file = $request->file('image');
$path = public_path() . '/advertisement_image/';
if (!file_exists($path)) {
mkdir($path, 666, true);
}
$name = uniqid() . '_' . $file->getClientOriginalName();
$image_resize = Image::make($file->getRealPath());
$image_resize->resize(300, 300);
if ($image_resize->save($path . $name)) {
$image = $name;
$input['image'] = $image;
}
}
} $status=success::create($input); if($status){ Session::flash('success','Information added successfully.'); }else{ Session::flash('error','Information cannot be added.'); } return redirect('backend/success'); }







Comments

Popular posts from this blog

laravel file manager sorting by time default

Ref :  https://github.com/UniSharp/laravel-filemanager/issues/337 To load files order by "time DESC" you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; } return strcmp($a->{$key_to_sort}, $b->{$key_to_sort}); }); return $arr_items; } with public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; ...

some important points for web developers and hosting

check dns https://www.whatsmydns.net/ https://check-host.net/ https://www.site24x7.com/ping-test.html attacks https://www.computerhope.com/unix/uping.htm https://vitux.com/linux-ping-command/ https://www.howtoforge.com/linux-ping-command/ https://www.poftut.com/linux-ping-command-tutorial-examples/ https://phoenixnap.com/kb/linux-ping-command-examples https://sandilands.info/sgordon/ping-flooding-dos-attack-in-a-virtual-network https://www.geeksforgeeks.org/ping-command-in-linux-with-examples/

Installing Admin LTE in Laravel

step 1:  Reference---  https://hdtuto.com/article/laravel-56-adminlte-bootstrap-theme-installation-example Step 2 : after completion first reference view this link:    https://github.com/JeroenNoten/Laravel-AdminLTE step 3:  For more additional information view this link:   https://github.com/jeroennoten/Laravel-AdminLTE#2-updating Now you are done statically : https://adminlte.io/blog/integrate-adminlte-with-laravel Steps: 1:  composer require jeroennoten/laravel-adminlte 2: 'providers' => [ .... JeroenNoten\LaravelAdminLte\ServiceProvider::class, ], 3: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=assets 5: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=config 6: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=views 7: for admin pannel php artisan ...