Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
coverage: none

- name: Install Composer dependencies
Expand Down
23 changes: 14 additions & 9 deletions app/Jobs/GenerateSocialShareImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace App\Jobs;

use App\Models\Article;
use Illuminate\Http\Response;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;

final class GenerateSocialShareImage
{
const TEXT_X_POSITION = 50;

const TEXT_Y_POSITION = 100;
const TEXT_Y_POSITION = 150;

const TEXT_COLOUR = '#161e2e';

Expand All @@ -23,16 +25,19 @@ final class GenerateSocialShareImage

public function __construct(private Article $article) {}

public function handle(ImageManager $image): mixed
public function handle(): Response
{
$image = new ImageManager(new Driver);
$text = wordwrap($this->article->title(), self::CHARACTERS_PER_LINE);

return $image->make(resource_path('images/'.self::TEMPLATE))
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
$font->file(resource_path('fonts/'.self::FONT));
$font->size(self::FONT_SIZE);
$font->color(self::TEXT_COLOUR);
})
->response('png');
return response(
$image->read(resource_path('images/' . self::TEMPLATE))
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
$font->file(resource_path('fonts/' . self::FONT));
$font->size(self::FONT_SIZE);
$font->color(self::TEXT_COLOUR);
})
->toPng()
)->header('Content-Type', 'image/png');
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"blade-ui-kit/blade-zondicons": "^1.5",
"codeat3/blade-simple-icons": "^5.0",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^2.7",
"intervention/image": "^3.0",
"laravel-notification-channels/telegram": "^5.0",
"laravel-notification-channels/twitter": "^8.1.1",
"laravel/framework": "^11.5",
Expand All @@ -32,6 +32,7 @@
"spatie/laravel-ignition": "^2.4",
"spatie/laravel-schedule-monitor": "^3.7",
"spatie/laravel-sitemap": "^7.2",
"spatie/pixelmatch-php": "^1.1",
"symfony/http-client": "^7.0",
"symfony/mailgun-mailer": "^7.0"
},
Expand Down
202 changes: 164 additions & 38 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading