Twitter card and Facebook og:image meta tags for sharing images
April 13, 2022
laravel londiniumTo further improve the metatags for social media, I created a laravel artisan command to create a Twitter Card Image.
The recommended size for a Twitter Card image size should be 1024 pixels by 512 pixels.
<meta property="og:image" content="https://mywebsite.net/assets/opengraph/theogimage.jpg"/>
<meta property="og:image:width" content="1024"/>
<meta property="og:image:height" content="512"/>
<meta name="twitter:image" content="http://www.yoursite.com/yourimage.jpg"/>
To install the reuqired php mods I ran:
apt-get install php8.0-imagick
apt-get install php8.0-gd
composer require intervention/image
After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.
In the $providers array add the service providers for this package.
Intervention\Image\ImageServiceProvider::class
Add the facade of this package to the $aliases array.
'Image' => Intervention\Image\Facades\Image::class
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"
php artisan storage:link
php artisan image:twittercard
And here is the code for the command:
Which creates an image like this:
To test the card use the twitter.com/validator
If you would like to contact me you can either use this form on londinium.com or via Twitter @andylondon