![](/img/trans.png)
[英]Can't write image data to path in laravel 8 using the Intervention library
[英]How to write text on image from form input in Laravel using intervention
我想使用輸入表單中的干預來創建帶有文本的圖像,我該怎么做,這是我的 controller
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();
}
$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', 0, 0, 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', 0, 0, function($font) {
$font->color(array(255, 255, 255, 0.5));
});
// Save Image to Path
$img->text($path);
$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', 0, 0, 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', 0, 0, function($font) {
$font->color(array(255, 255, 255, 0.5));
});
// Save Image to Path
$img->save($path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.