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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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": "^5.0",
"guzzlehttp/guzzle": "^7.2",
"innocenzi/bluesky-notification-channel": "^0.2.0",
"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 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
Loading