سلام دوستان، من میخوام یه متنی رو بگیرم و اونو به عکس تبدیل کنم و در صفحه نمایش بدم. برای تبدیل متن به عکس از کتابخانه ی GD استفاده کردم. فایل زیر محتوای StudInsertController هست که وقتی کاربر نوشته رو داخل تکست باکس وارد کرد به این کنترلر میره:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class StudInsertController extends Controller {
public function insertform(){
return view('stud_create');
}
public function insert(Request $request){
$text = $request->input('stud_name');
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// Replace path by your own font path
$font = 'C:\laravel\public\fonts\arial.ttf';
// Add some shadow to the text
//imagettftext($im, 20, 0, 11, 21, $grey, $font, 'hi');
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
//imagedestroy($im);
return view('stud_create');
}
}
کد زیر هم فایل stud_create.php است:
<html>
<head>
<title>Student Management | Add</title>
</head>
<body>
<form action = "/create" method = "post">
<img src='StudeInsertController.php' border="0">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<table>
<tr>
<td>Name</td>
<td><input type='text' name='stud_name' /></td>
</tr>
<tr>
<td colspan = '2'>
<input type = 'submit' value = "Add student"/>
</td>
</tr>
</table>
</form>
</body>
</html>
ولی خروجیی که نشون میده به این صورته:
Capture.PNG