PHP code example of abordage / og-images
1. Go to this page and download the library: Download abordage/og-images library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abordage / og-images example snippets
use Abordage\OpenGraphImages\OpenGraphImages;
$text = 'The adventures first, explanations take such a dreadful time!';
$path = __DIR__ . '/your-name-for-image.png';
$openGraphImage = new OpenGraphImages($config);
$openGraphImage->make($text)->save($path);
$openGraphImage = new OpenGraphImages($config);
// for <og:image>
$openGraphImage->make($text)->save($path);
// or
$openGraphImage->make($text, 'opengraph')->save($path);
// for <twitter:image>
$openGraphImage->make($text, 'twitter')->save($path);
// for <vk:image>
$openGraphImage->make($text, 'vk')->save($path);
// custom size
$openGraphImage->makeCustom($text, 600, 400)->save($path);
$openGraphImage = new OpenGraphImages($config);
$imageBlob = $openGraphImage->make($text)->get();
$openGraphImage->make($text, 'twitter')->get();
$imageSizes = $openGraphImage->getImageSizes();
// return [
// 'width' => 1200,
// 'height' => 600
// ];
$config = [
/*
|--------------------------------------------------------------------------
| Background Color
|--------------------------------------------------------------------------
|
| Supported: HEX, RGB or RGBA format
|
*/
'background_color' => '#474761',
/*
|--------------------------------------------------------------------------
| Text Color
|--------------------------------------------------------------------------
|
| Supported: HEX, RGB or RGBA format
|
*/
'text_color' => '#eee',
/*
|--------------------------------------------------------------------------
| App Name
|--------------------------------------------------------------------------
|
| Set null to disable
|
| Supported: string or null
|
*/
'app_name' => null,
/*
|--------------------------------------------------------------------------
| App Name Text Color
|--------------------------------------------------------------------------
|
| Supported: HEX, RGB or RGBA format
|
*/
'app_name_color' => '#eee',
/*
|--------------------------------------------------------------------------
| App Name Decoration Color
|--------------------------------------------------------------------------
|
| Supported: HEX, RGB or RGBA format
|
*/
'app_name_decoration_color' => '#fb3361',
/*
|--------------------------------------------------------------------------
| Text Alignment
|--------------------------------------------------------------------------
|
| Multiline text alignment
|
| Supported: "left", "center", "right"
|
*/
'text_alignment' => 'left',
/*
|--------------------------------------------------------------------------
| Text Sticky
|--------------------------------------------------------------------------
|
| Supported: "left", "center", "right"
|
*/
'text_sticky' => 'center',
/*
|--------------------------------------------------------------------------
| App Name Position
|--------------------------------------------------------------------------
|
| Supported: "top-left", "top-center", "top-right",
| "bottom-left", "bottom-center", "bottom-right"
|
*/
'app_name_position' => 'bottom-center',
/*
|--------------------------------------------------------------------------
| App Name Decoration Style
|--------------------------------------------------------------------------
|
| Set null to disable
|
| Supported: "line", "label", "rectangle", null
|
*/
'app_name_decoration_style' => 'line',
/*
|--------------------------------------------------------------------------
| Font Size
|--------------------------------------------------------------------------
|
*/
'font_size' => 55,
/*
|--------------------------------------------------------------------------
| App Name Font Size
|--------------------------------------------------------------------------
|
*/
'app_name_font_size' => 30,
/*
|--------------------------------------------------------------------------
| Text Font
|--------------------------------------------------------------------------
|
| If set null, will be used Preset Font (Roboto Regular)
|
| Supported: "absolute/path/to/your/font.ttf", null
|
*/
'font_path' => null,
/*
|--------------------------------------------------------------------------
| App Name Font
|--------------------------------------------------------------------------
|
| If set null, will be used Preset Font (Roboto Medium)
|
| Supported: "absolute/path/to/your/font.ttf", null
|
*/
'app_name_font_path' => null,
];