1. Go to this page and download the library: Download simonhamp/the-og 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/ */
simonhamp / the-og example snippets
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\Image;
(new Image())
->accentColor('#cc0000')
->border()
->url('https://example.com/blog/some-blog-post-url')
->title('Some blog post title that is quite big and quite long')
->description(<<<'TEXT'
Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words.
Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words.
TEXT)
->background(Background::JustWaves, 0.2)
->save(__DIR__.'/test.png');
$image = new Image;
$image->save('/path/to/your/image.png');
$image = (new Image())->toString();
// $service here could be an AWS\S3\S3Client, for example
$service->putObject([
'Key' => 'example-image.png',
'Body' => $image,
'ContentType' => 'image/png',
]);
use Intervention\Image\Encoders\WebpEncoder;
$image->toString(encoder: new WebpEncoder);
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\BackgroundPlacement;
(new Image)->background(
background: Background::JustWaves,
opacity: 0.5,
placement: BackgroundPlacement::Cover
);
use SimonHamp\TheOg\BorderPosition;
$image = new Image;
$image->border(BorderPosition::Top, 'pink', 10);
$image = new Image;
$image->border(BorderPosition::None);
use SimonHamp\TheOg\Theme;
$image = new Image;
$image->theme(Theme::Dark);
use SimonHamp\TheOg\Theme\Fonts\Inter;
use SimonHamp\TheOg\Theme\Theme;
$theme = new Theme(
accentColor: '#247BA0',
backgroundColor: '#ECEBE4',
baseColor: '#153B50',
baseFont: Inter::bold(),
callToActionBackgroundColor: '#153B50',
callToActionColor: '#ECEBE4',
descriptionColor: '#429EA6',
descriptionFont: Inter::light(),
titleFont: Inter::black(),
);
$image = new Image;
$image->theme($theme);
use SimonHamp\TheOg\Interfaces\Font;
class CustomFont implements Font
{
public function path(): string
{
return '/path/to/your/font/source/file.ttf';
}
}
$font = new CustomFont;
$theme = new Theme(
baseFont: $font,
);
use SimonHamp\TheOg\Theme\Background;
$background = new Background('/path/to/your/image.png');
$theme = new Theme(
background: $background,
);
$image = (new Image)->theme($theme);
// Or
$image->background($background);
$image = new Image;
$image->backgroundColor('seagreen')
->background($customBackground);
use Intervention\Image\Interfaces\ImageInterface;
public function render(ImageInterface $image)
{
$image->drawCircle(10, 10, function ($circle) {
$circle->radius(150);
$circle->background('lightblue');
$circle->border('b53717', 1);
});
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.