Skip to content

Commit 615a913

Browse files
committed
WIP
1 parent 0e2ccd8 commit 615a913

File tree

12 files changed

+1273
-617
lines changed

12 files changed

+1273
-617
lines changed
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Str;
8+
use Intervention\Image\AbstractFont;
9+
use Intervention\Image\Facades\Image;
10+
use Laminas\Stdlib\StringWrapper\MbString;
11+
12+
class CoverController extends Controller
13+
{
14+
/**
15+
* @param \Illuminate\Http\Request $request
16+
*
17+
* @return mixed
18+
*/
19+
public function image(Request $request)
20+
{
21+
$text = $request->input('text', config('site.name'));
22+
23+
$key = "cover-" . sha1($text) . Str::random(100);
24+
25+
$data = Cache::remember($key, now()->addHours(4), function () use ($text) {
26+
$width = 1920;
27+
$height = 1080;
28+
29+
$start_x = 100;
30+
$start_y = $height / 2 + 30;
31+
$max_len = 28;
32+
33+
$mbWrap = new MbString();
34+
$textWrap = $mbWrap->wordWrap($text, $max_len);
35+
36+
$lines = Str::of($textWrap)->explode("\n");
37+
38+
$font_size = min(110 - $lines->count() * 5, 110);
39+
$font_height = min(75 - $lines->count() * 5, 75);
40+
41+
$y = round($start_y - ((count($lines) - 1) * $font_height));
42+
43+
$image = Image::make(public_path('/img/share/socials.png'), 0, 0);
44+
45+
$image->fit($width, $height, fn($constraint) => $constraint->aspectRatio());
46+
47+
$lines->each(function ($line) use ($image, $start_x, $font_size, $font_height, &$y, $lines) {
48+
49+
$image->text($line, $start_x, round($y), fn(AbstractFont $font) => $font->file(public_path('fonts/cover.ttf'))
50+
->size($font_size)
51+
->color('#fff')
52+
->align('left')
53+
->valign('center'));
54+
55+
$y += $font_height * 2;
56+
});
57+
58+
return (string) $image->encode('data-url');
59+
});
60+
61+
return Image::make($data)->encode('jpg', 75)->response();
62+
}
63+
}

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"doctrine/dbal": "^3.7",
1111
"guzzlehttp/guzzle": "^7.2",
1212
"hotwired/turbo-laravel": "^1.12",
13+
"intervention/image": "^2.7",
1314
"jolicode/jolitypo": "^1.4",
15+
"laminas/laminas-stdlib": "^3.18",
1416
"laravel/framework": "^10.31",
1517
"laravel/sanctum": "^3.2",
1618
"laravel/scout": "^10.5",

composer.lock

+144-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/fonts/cover.ttf

159 KB
Binary file not shown.

public/img/logos/docker.svg

+5
Loading

public/img/share/socials.png

225 KB
Loading

resources/views/html.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<link rel="alternate" type="application/atom+xml" title="Новости" href="/rss/feed">
1616

1717
<x-meta
18-
title="{!! View::getSection('title') ? strip_tags(View::getSection('title')) . ' | ' : '' !!}{!! config('site.name') !!}"
18+
title="{!! View::getSection('title') ? strip_tags(View::getSection('title')) . ' | '. config('site.name') : config('site.name') !!}"
1919
description="{!! View::getSection('description', config('site.description')) !!}"
20-
{{-- image="{{ asset('/img/external.png') }}" --}}
20+
image="{!! URL::signedRoute('cover', ['text' => View::getSection('title', config('site.description'))]) !!}"
2121
{{-- csp="*.laravel.su *.gravatar.com *.githubusercontent.com" --}} />
2222

2323
<link rel="preconnect" href="https://fonts.googleapis.com">

resources/views/layout.blade.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
<li><a href="{{ route('feed') }}" class="nav-link px-3 link-body-emphasis">Трибуна</a></li>
2929
<li><a href="{{ route('packages') }}" class="nav-link px-3 link-body-emphasis">Пакеты</a></li>
3030
<li><a href="{{ route('jobs') }}" class="nav-link px-3 link-body-emphasis">Работа</a></li>
31-
<li><a href="{{ route('resources') }}"
32-
class="nav-link px-3 link-body-emphasis position-relative">Ресурсы
31+
<li><a href="{{ route('courses') }}" class="nav-link px-3 link-body-emphasis position-relative">Курсы
3332
<span class="badge bg-primary position-absolute top-0 start-100 translate-middle mt-2">Новое</span></a>
3433
</li>
3534
</ul>
@@ -124,7 +123,7 @@ class="link-dark btn avatar avatar-sm text-bg-dark border border-tertiary-subtle
124123
<a href="{{ route('jobs') }}" class="nav-link p-0">Вакансии</a>
125124
</li>
126125
<li class="nav-item mb-2">
127-
<a href="{{ route('courses') }}" class="nav-link p-0">Видео уроки</a>
126+
<a href="{{ route('resources') }}" class="nav-link p-0">Ресурсы</a>
128127
</li>
129128
</ul>
130129
</div>

0 commit comments

Comments
 (0)