How to use logo as watermark on an image in laravel

 



 StudentController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Image;
class StudentController extends Controller
{
    public function create()
    {
        return view('create');
    }

    public function store(Request $request)
    {
        if($request->hasfile('image')){

            $image=$request->file('image');
        $file_name=time().'.'.$image->getClientOriginalExtension();
        $image_resize = Image::make($image->getRealPath());              
        $image_resize->resize(400, 400);

        if(!is_null($request->watermark))
   {
        $watermark = Image::make($request->watermark);
         $watermark->resize(400, 50);
$image_resize->insert($watermark, 'bottom');
}
        $image_resize->save('images/'.$file_name);

    }
    return back()->with('success','done');


    }
}


View File

create.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Image Watermark</title>
</head>
<body>

    <h2>Image form</h2>
    @if(Session::has('success'))
    <label style="color: green;">{{Session::get('success')}}</label>
    @endif
    <form action="/StudentCreate" method="POST" enctype="multipart/form-data">
        {{csrf_field()}}
        <label>Student name</label>
        <input type="text" name="name" placeholder="Student name">
        <label>Student Photo</label>
        <input type="file" name="image"  >
        <label>Watermark image</label>
        <input type="file" name="watermark"  >
        <input type="submit" value="Save">
    </form>

</body>
</html>

No comments

Powered by Blogger.