-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCoverController.php
executable file
·50 lines (40 loc) · 1.35 KB
/
CoverController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;
use Intervention\Image\Typography\FontFactory;
class CoverController extends Controller
{
/**
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function image(Request $request)
{
$text = Str::of($request->input('text', config('site.name')))
->replaceMatches('/[^\p{L}\p{N}\p{Z}\p{P}]/u', '') // remove all non-letters, non-numbers, non-punctuation
->trim()
->squish()
->limit(60);
$width = 1920;
$height = 1080;
$start_x = 230;
$start_y = $height / 2 + 40;
$manager = new ImageManager(Driver::class);
$image = $manager->read(public_path('/img/share/socials.png'));
$image
->text($text, $start_x, $start_y, fn (FontFactory $font) => $font->filename(public_path('fonts/cover.ttf'))
->size(90)
->color('#222222')
->align('left')
->wrap(1100)
->lineHeight(1.6)
->valign('center'));
$image->scaleDown($width, $height);
return response($image->toJpeg(75))
->header('Content-Type', 'image/jpeg');
}
}