Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to intervantion v3 #1189

Merged
merged 15 commits into from
Feb 28, 2025
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ 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: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction

Expand Down
30 changes: 21 additions & 9 deletions app/Jobs/GenerateSocialShareImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace App\Jobs;

use App\Models\Article;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
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 +26,25 @@ 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 Cache::remember(
'articleSocialImage-' . $this->article->id,
now()->addDay(),
fn () =>
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')
->header('Cache-Control', 'max-age=86400, public')
);
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"codeat3/blade-simple-icons": "^6.2",
"guzzlehttp/guzzle": "^7.2",
"innocenzi/bluesky-notification-channel": "^0.2.0",
"intervention/image": "^2.7",
"intervention/image": "^3.0",
"laravel-notification-channels/telegram": "^6.0",
"laravel-notification-channels/twitter": "^8.1.1",
"laravel/framework": "^11.5",
Expand Down Expand Up @@ -41,7 +41,8 @@
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.0",
"pestphp/pest": "^3.0",
"pestphp/pest-plugin-laravel": "^3.0"
"pestphp/pest-plugin-laravel": "^3.0",
"spatie/pixelmatch-php": "^1.1"
},
"autoload": {
"files": [
Expand Down
Loading