Skip to content

Commit 774ec5e

Browse files
committed
WIP
1 parent 036e16a commit 774ec5e

File tree

4 files changed

+502
-1969
lines changed

4 files changed

+502
-1969
lines changed

app/Jobs/GenerateSocialShareImage.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace App\Jobs;
44

55
use App\Models\Article;
6+
use Intervention\Image\Drivers\Gd\Driver;
67
use Intervention\Image\ImageManager;
78

89
final class GenerateSocialShareImage
910
{
1011
const TEXT_X_POSITION = 50;
1112

12-
const TEXT_Y_POSITION = 100;
13+
const TEXT_Y_POSITION = 150;
1314

1415
const TEXT_COLOUR = '#161e2e';
1516

@@ -23,16 +24,19 @@ final class GenerateSocialShareImage
2324

2425
public function __construct(private Article $article) {}
2526

26-
public function handle(ImageManager $image): mixed
27+
public function handle(): mixed
2728
{
29+
$image = new ImageManager(new Driver);
2830
$text = wordwrap($this->article->title(), self::CHARACTERS_PER_LINE);
2931

30-
return $image->make(resource_path('images/'.self::TEMPLATE))
31-
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
32-
$font->file(resource_path('fonts/'.self::FONT));
33-
$font->size(self::FONT_SIZE);
34-
$font->color(self::TEXT_COLOUR);
35-
})
36-
->response('png');
32+
return response(
33+
$image->read(resource_path('images/' . self::TEMPLATE))
34+
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
35+
$font->file(resource_path('fonts/' . self::FONT));
36+
$font->size(self::FONT_SIZE);
37+
$font->color(self::TEXT_COLOUR);
38+
})
39+
->toPng()
40+
)->header('Content-Type', 'image/png');
3741
}
3842
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"blade-ui-kit/blade-zondicons": "^1.5",
1313
"codeat3/blade-simple-icons": "^5.0",
1414
"guzzlehttp/guzzle": "^7.2",
15-
"intervention/image": "^2.7",
15+
"intervention/image": "^3.0",
1616
"laravel-notification-channels/telegram": "^5.0",
1717
"laravel-notification-channels/twitter": "^8.1.1",
1818
"laravel/framework": "^11.5",

composer.lock

Lines changed: 98 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)