如何使用干预从Laravel中的表单输入在图像上写文本

我想使用输入表单中的Intervention创建带有文本的图像,我该怎么做?

public function store(Request $request)


        if($request->hasFile('content'))
        {
          $filenameWithExt = $request->file('content')->getclientOriginalName();
          $filename = pathinfo($filenameWithExt,PATHINFO_FILENAME);
          $extension = $request->file('content')->getclientOriginalExtension();
          $fileNameToStore = $filename.'_'.time().'.'.$extension;
          $path = $request->file('content')->storeAs('public/content',$fileNameToStore);
        }
        else
        {
            $fileNameToStore = 'No Image,Music and Video selected please! check and try again.';
        }

        $post = new Post;
        $post->title = $request->input('title');
        $post->body = $request->input('body');
        $post->subcategory_id = implode(',',$request->input('subcategory_id') );
        $post->user_id = auth()->user()->id;
        $post->content = $fileNameToStore;
        $post->save();

    }
just483 回答:如何使用干预从Laravel中的表单输入在图像上写文本

$image = Input::file('image');

// Define File Name and Path
$filename  = time() . '.' . $image->getClientOriginalExtension();
$path = ('image/path/' . $filename);

// create Image from Input
$img = Image::make($image->getRealPath());

// write text
$img->text('The quick brown fox jumps over the lazy dog.');

// write text at position x,y 
$img->text('The quick brown fox jumps over the lazy dog.',120,100);

// use callback to define details
$img->text('foo',function($font) {
    $font->file('foo/bar.ttf');
    $font->size(24);
    $font->color('#fdf6e3');
    $font->align('center');
    $font->valign('top');
    $font->angle(45);
});

// draw transparent text
$img->text('foo',function($font) {
    $font->color(array(255,255,0.5));
});

// Save Image to Path 
$img->text($path);

参考: http://image.intervention.io/api/text

,
$image = Input::file('image');

// Define File Name and Path
$filename  = time() . '.' . $image->getClientOriginalExtension();
$path = ('image/path/' . $filename);

// create Image from Input
$img = Image::make($image->getRealPath());

// write text
$img->text('The quick brown fox jumps over the lazy dog.');

// write text at position x,0.5));
});

// Save Image to Path

$img->save($path);
本文链接:https://www.f2er.com/3161243.html

大家都在问