CrestRoad/laravel/app/Http/Controllers/Theoriginal1doctorControlle...

120 lines
4.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Storage;
use Config;
class Theoriginal1doctorController extends Controller
{
protected $page_title = 'The Original1 Doctor';
protected $page_description = 'Theoriginal1doctor';
protected $table_fields = [
'doctor_name' => 'Doctor Name',
'doctor_code' => 'Doctor Code',
'speciality' => 'Speciality',
'city' => 'City'
];
public function __construct()
{
$this->_tablename = 'theorignal1doctor';
$this->_viewname = 'theoriginal1doctor';
Config::set('page_title', $this->page_title);
Config::set('page_description', $this->page_description);
}
public function index(Request $request)
{
return view($this->_viewname . '.index');
}
public function postindex(Request $request)
{
$post = $request->except('_token');
$post['doctor_name'] = $request->doctor_name;
$post['city'] = $request->city;
if ($request->file('doctor_photo')) {
$post['doctor_photo'] = $this->_uploadMedia($request, 'doctor_photo', $this->_viewname);
$folder = storage_path('app/public/' . $this->_viewname);
$post['doctor_photo'] = $this->_resize($folder, $post['doctor_photo'], 800, 0, true);
//exec('cd '.$folder.'; convert '.$post['doctor_photo'].' -resize 800x -quality 80 '.$post['doctor_photo']);
}
$post['status'] = 1;
$id = DB::table($this->_tablename)->insertGetId($post);
$post['id'] = $id;
$request->session()->put($this->_viewname, $post);
return redirect('/crop');
}
public function crop(Request $request)
{
$post = $request->session()->get($this->_viewname);
return view($this->_viewname . '.crop')
->with('image', $post['doctor_photo'])
->with('folder', $this->_viewname);
}
public function postcrop(Request $request)
{
$card = $request->session()->get($this->_viewname);
$post = $request->input();
$data = explode(',', $post['image']);
$image = base64_decode($data[1]);
Storage::disk('public')->put($this->_viewname . '/' . $card['doctor_photo'], $image);
return redirect('/generate');
}
public function generate(Request $request)
{
$card = $request->session()->get($this->_viewname);
$record = DB::table($this->_tablename)->where('id', $card['id'])->first();
//echo '<pre>'; print_r($record); exit;
$folder = storage_path('app/public/' . $this->_viewname);
$templatename = 'template.png';
$templateImage = $this->retimage($folder . '/' . $templatename);
$photoimg = $this->retimage($folder . '/' . $record->doctor_photo);
$photosize = getimagesize($folder . '/' . $record->doctor_photo);
$outputImage = imagecreatetruecolor(563, 1000);
imagecopyresized($outputImage, $photoimg, 96, 269, 0, 0, 370, 520, $photosize[0], $photosize[1]);
imagecopyresized($outputImage, $templateImage, 0, 0, 0, 0, 563, 1000, 563, 1000);
$font = storage_path('app') . '/fonts/Adelon-BoldIta.ttf';
$white = imagecolorallocate($outputImage, 255, 255, 255);
$box = imagettfbbox(23, 0, $font, $record->doctor_name);
$x = 87 + ((477 - 87) - $box[2])/2;
imagettftext($outputImage, 23, 0, $x, 825, $white, $font, $record->doctor_name);
$box = imagettfbbox(18, 0, $font, $record->city);
$x = 87 + ((477 - 87) - $box[2])/2;
imagettftext($outputImage, 18, 0, $x, 866, $white, $font, $record->city);
$filename = str_slug($record->doctor_name, "_") . '-' . $record->id . '.png';
imagepng($outputImage, $folder . '/' . $filename);
imagedestroy($outputImage);
$post['imagename'] = $filename;
$request->session()->put($this->_viewname, $post);
DB::table($this->_tablename)->where('id', $card['id'])->update(['doctor_photo' => $filename, 'status' => 1]);
//return view($this->_viewname.'.download')->with('image', $post['imagename'])->with('storage', $this->_viewname);
return redirect('/download');
}
public function download(Request $request)
{
$post = $request->session()->get($this->_viewname);
return view($this->_viewname . '.download')->with('image', $post['imagename'])->with('storage', $this->_viewname);
}
}