Skip to content

Commit f779116

Browse files
authored
Upgrade to intervantion v3 (#1189)
1 parent 875aeb9 commit f779116

File tree

8 files changed

+1524
-3504
lines changed

8 files changed

+1524
-3504
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ jobs:
2828
uses: shivammathur/setup-php@v2
2929
with:
3030
php-version: 8.3
31-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
31+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
3232
coverage: none
3333

34+
- name: Setup Node
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: '22.x'
38+
3439
- name: Install Composer dependencies
3540
run: composer install --prefer-dist --no-interaction
3641

app/Jobs/GenerateSocialShareImage.php

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

55
use App\Models\Article;
6+
use Illuminate\Http\Response;
7+
use Illuminate\Support\Facades\Cache;
8+
use Intervention\Image\Drivers\Gd\Driver;
69
use Intervention\Image\ImageManager;
710

811
final class GenerateSocialShareImage
912
{
1013
const TEXT_X_POSITION = 50;
1114

12-
const TEXT_Y_POSITION = 100;
15+
const TEXT_Y_POSITION = 150;
1316

1417
const TEXT_COLOUR = '#161e2e';
1518

@@ -23,16 +26,25 @@ final class GenerateSocialShareImage
2326

2427
public function __construct(private Article $article) {}
2528

26-
public function handle(ImageManager $image): mixed
29+
public function handle(): Response
2730
{
31+
$image = new ImageManager(new Driver);
2832
$text = wordwrap($this->article->title(), self::CHARACTERS_PER_LINE);
2933

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');
34+
return Cache::remember(
35+
'articleSocialImage-' . $this->article->id,
36+
now()->addDay(),
37+
fn () =>
38+
response(
39+
$image->read(resource_path('images/' . self::TEMPLATE))
40+
->text($text, self::TEXT_X_POSITION, self::TEXT_Y_POSITION, function ($font) {
41+
$font->file(resource_path('fonts/' . self::FONT));
42+
$font->size(self::FONT_SIZE);
43+
$font->color(self::TEXT_COLOUR);
44+
})
45+
->toPng()
46+
)->header('Content-Type', 'image/png')
47+
->header('Cache-Control', 'max-age=86400, public')
48+
);
3749
}
3850
}

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"codeat3/blade-simple-icons": "^6.2",
1414
"guzzlehttp/guzzle": "^7.2",
1515
"innocenzi/bluesky-notification-channel": "^0.2.0",
16-
"intervention/image": "^2.7",
16+
"intervention/image": "^3.0",
1717
"laravel-notification-channels/telegram": "^6.0",
1818
"laravel-notification-channels/twitter": "^8.1.1",
1919
"laravel/framework": "^11.5",
@@ -41,7 +41,8 @@
4141
"mockery/mockery": "^1.6",
4242
"nunomaduro/collision": "^8.0",
4343
"pestphp/pest": "^3.0",
44-
"pestphp/pest-plugin-laravel": "^3.0"
44+
"pestphp/pest-plugin-laravel": "^3.0",
45+
"spatie/pixelmatch-php": "^1.1"
4546
},
4647
"autoload": {
4748
"files": [

0 commit comments

Comments
 (0)