intervention/image error when capture with mobile camera - laravel

When i uploaded image to my website from capture image from mobile camera no from the gallery
and it say " Image source not readable"
this is my code
$fileName = create_random_name() . '.' . $image->getClientOriginalExtension();
$img = Image::make($image->getRealPath());
$img->stream();
Storage::disk('local')->put("public/images/{$directory}/".$fileName,$img,'public');
return $fileName;

Maybe this code will help you:
Storage::disk('local')->put($newFilename, file_get_contents($file));

Related

Image pixelate on resize browser( responsive design ) after upload on laravel

After upload the image, on resize browser, or enter the project on the mobile browser, quality of image is very weak, how can i improve that ?
if($request->hasFile('image')){
$image = $request->file('image');
$filename = $request->name;
$foldername = $request->name;
$imagename = $filename .'.' . $request->image->extension();
$path = public_path('images/produse/'. $filename .'/');
if(!File::exists($path)){
File::makeDirectory($path, 0777, true, true);
}
Image::make($image)->resize(200, 200)->save( public_path('images/produse/' . $foldername . '/' . $imagename ));
}
You should try with a larger resize resolution. For example (800, 600)

Laravel - Image source not readable after publish website

I was created simple CMS and everything works at localhost. After published website I can't upload image. I have an error "Image source not readable". I changed chmod upload's folder to 777.
My code:
$minphoto_path = 'uploads/img';
$minphoto = $request->minphoto;
$minphoto_new_name = time().$minphoto->getClientOriginalName();
$minphoto->move($minphoto_path, $minphoto_new_name);
$img = Image::make(public_path($minphoto_path . '/' .$minphoto_new_name))->resize(240, 338)->save(public_path($minphoto_path . '/' .$minphoto_new_name));
Try upload that way:
$file = Input::file('file');
$fileName = time() . '-' . $file->getClientOriginalName();
$file->move('uploads', $fileName);
$img = Image::make($file->getRealPath())->resize(320, 240)
->save('public/uploads/'. $file->getClientOriginalName());
Or shorter:
$file = Input::file('file');
$img = Image::make($file)->resize(320, 240)
->save('public/uploads/'. $file->getClientOriginalName());

Laravel resize and upload to storage

I am trying to resize, rename and upload the image using laravel Storage, intervention on laravel5.
Here is my upload code:
if( $request->file('logo_image') ){
$logo_path = $request->file('logo_image')->store('university/'.Auth::User()->id);
if ( $logo_path ){
Storage::delete($university->logo_image);
}
$university->logo_image = $logo_path;
}
$university->update();
It is storing the image on folder like: storage/app/public/university/1/fjkdhjkfdh.jpg
Now I want to rename image name like university-name.jpg and also resize and upload to sam directory.
So I should have two images one is storage/app/public/university/1/university-name.jpg.jpg
and other is storage/app/public/university/1/thumbnail/university-name.jpg
I play around with this for the whole day but no success.
if(Input::file())
{
$image = Input::file('image');
$filename = time() . '.' . $image->getClientOriginalExtension();
$path = public_path('profilepics/' . $filename);
Image::make($image->getRealPath())->resize(200, 200)->save($path);
$user->image = $filename;
$user->save();
}
Please someone can help me?
Thanks in advance.

Image resize error using intervention in laravel 5

I am using intervention image to resize image and then save it to a destination folder. But its not working for me. I am getting error like, "Image source not readable".
Pls see the below code:
$image_name = $file->getClientOriginalName();
$thumbName = 'thumb_'. $image_name;
$destinationPath = public_path() . '/uploads/';
$thumbdestinationPath = public_path() . '/uploads/thumbnails/';
$imgUrl = URL::to('/').'/public/uploads/'.$image_name;
$thumbUrl = URL::to('/').'/public/uploads/thumbnails/'.$image_name;
$upload_success = $file->move( $destinationPath, $image_name);
if ($upload_success) {
Image::make($file->getRealPath())->fit('120','120')->save($thumbdestinationPath );
}
You need to give the name of image:
if ($upload_success) {
Image::make($file->getRealPath())->fit('120','120')->save($thumbdestinationPath . $image_name );
}

Laravel 5 image resize

I use Laravel 5 and have a form to upload a image. When saving the file I have in my controller methods to get the image and put it in a directory:
if ($request->hasFile('picture')) {
$destinationPath = 'uploads';
$filename = $image->getClientOriginalName();
$extension = $image->getClientOriginalExtension(); // add
$picture = sha1($filename . time()) . '.' . $extension; //add
$offer->image = $picture;
$image->move($destinationPath, $picture);
}
$offer->save();
Before I save the file I would like to resize the file with a max. width of 800px. Is there a image resize or compression function in Laravel available?
What would be the best idea to do this?
You can install and use package, similar to intervention.
Example from official website:
$img = Image::make('public/foo.jpg');
$img->resize(320, 240);
$img->insert('public/watermark.png');
$img->save('public/bar.jpg');
Image::make($request->file('image'))->resize(462, 462)->save('upload_path/filename.jpg'));
try this code

Resources