簡體   English   中英

如何使用干預從 Laravel 中的表單輸入在圖像上寫入文本

[英]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);

參考: 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 , 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM