PHPackages                             simonhamp/the-og - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. simonhamp/the-og

ActiveLibrary[Image &amp; Media](/categories/media)

simonhamp/the-og
================

A minimalist OpenGraph Image Generator for PHP

v0.7.0(8mo ago)29340.0k↑52.2%17[2 issues](https://github.com/simonhamp/the-og/issues)[1 PRs](https://github.com/simonhamp/the-og/pulls)MITPHPPHP ^8.2CI passing

Since Jan 2Pushed 8mo ago4 watchersCompare

[ Source](https://github.com/simonhamp/the-og)[ Packagist](https://packagist.org/packages/simonhamp/the-og)[ GitHub Sponsors](https://github.com/simonhamp)[ RSS](/packages/simonhamp-the-og/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (26)Used By (0)

[![](https://github.com/simonhamp/the-og/raw/main/thumbnail.png?raw=true)](https://github.com/simonhamp/the-og/blob/main/thumbnail.png?raw=true)

[![Build Status](https://camo.githubusercontent.com/40b2c1597f9c8257dc3743c695492dabf54e686ba32cde7b000cb0cb30d1fa11/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73696d6f6e68616d702f7468652d6f672f72756e2d74657374732e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d7465737473)](https://github.com/simonhamp/the-og/actions)[![Latest Stable Version](https://camo.githubusercontent.com/b58aa73888d85ffa7c67a08f12a6470d1bee3b4e7bdec40fe7b0326d4508dc97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696d6f6e68616d702f7468652d6f673f7374796c653d666f722d7468652d6261646765266c6162656c3d6c6174657374)](https://github.com/simonhamp/the-og/releases)[![Total Downloads](https://camo.githubusercontent.com/bf3b986863f3c058b50ce6a0e5065eaef7ff4504d9327e2368fa71d91fcdd2ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696d6f6e68616d702f7468652d6f673f7374796c653d666f722d7468652d6261646765266c6162656c3d696e7374616c6c73)](https://packagist.org/packages/simonhamp/the-og/stats)[![License](https://camo.githubusercontent.com/e23462e8050f157260be0a51db265e0c99919c91fc1523941eefe4f9c667f0d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73696d6f6e68616d702f7468652d6f673f7374796c653d666f722d7468652d6261646765266c6162656c3d6c6963656e7365)](https://github.com/simonhamp/the-og/blob/main/LICENSE)

The OG
======

[](#the-og)

An OpenGraph image generator written purely in PHP, so you don't need to install another runtime somewhere or a whole browser instance just to create a dynamic PNG.

Sponsorship
-----------

[](#sponsorship)

The OG is completely free to use for personal or commercial use. If it's making your job easier, or you just want to make sure it keeps being supported and improved, I'd really appreciate your donations!

[Donate now via GitHub Sponsors](https://github.com/sponsors/simonhamp)

If you're using The OG, I'd love to see your creations! Please send me a tweet/toot ([@simonhamp](https://twitter.com/simonhamp), [@simonhamp@phpc.social](https://phpc.social/@simonhamp)) with some links so I can see how you're using The OG in the wild.

Thank you 🙏

Sponsors
--------

[](#sponsors)

[Laradir](https://laradir.com/?ref=the-og-github) - Connecting the best Laravel Developers with the best Laravel Teams.
[quantumweb](https://quantumweb.co/?ref=simonhamp/the-og-github) - A bare-metal web agency. Less layers, better results.
[RedGalaxy](https://www.redgalaxy.co.uk) - A web application development studio based in Cambridgeshire, building solutions to help businesses improve efficiency and profitability.
[Sevalla](https://sevalla.com/?utm_source=nativephp&utm_medium=Referral&utm_campaign=homepage) - Host and manage your applications, databases, and static sites in a single, intuitive platform.

Installation
------------

[](#installation)

Install via Composer:

```
composer require simonhamp/the-og
```

Usage
-----

[](#usage)

Using The OG is really simple. Here's a basic example:

```
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(save('/path/to/your/image.png');
```

If you prefer to store your image somewhere other than the local filesystem (e.g. storing it on Amazon S3) you can use the `toString()` method.

`toString()` will return the rendered image as a binary string:

```
$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',
]);
```

This will send the raw binary data directly to the external service without needing to write the image to a file on the local disk first.

#### Image formats

[](#image-formats)

By default, The OG encodes images in **PNG format**.

If you wish to use a different format, however, you can! Simply pass an instance of the relevant [`intervention/image` encoder](https://github.com/Intervention/image/tree/develop/src/Encoders)to the `save()` or `toString()` methods:

```
use Intervention\Image\Encoders\WebpEncoder;

$image->toString(encoder: new WebpEncoder);
```

### Colors

[](#colors)

Throughout The OG, colors can be expressed as hex codes, rgba, or HTML named colors.

### Backgrounds

[](#backgrounds)

The OG comes with a number of built-in background patterns that you can use to add some texture to your image. You can find all of these defined in the [`Background` enum](https://github.com/simonhamp/the-og/blob/main/src/Background.php).

Backgrounds can be set to `Repeat` or `Cover` and have opacity too:

```
use SimonHamp\TheOg\Background;
use SimonHamp\TheOg\BackgroundPlacement;

(new Image)->background(
    background: Background::JustWaves,
    opacity: 0.5,
    placement: BackgroundPlacement::Cover
);
```

It also supports custom background images from local or remote sources. See the [Custom Background Images](#custom-background-images) section below.

### Borders

[](#borders)

Borders provide a subtle variation of color and texture to your image by framing one, or multiple edges of the image with a single band of color—usually the theme's `accentColor`.

Borders are usually defined as part of the theme, but you can override the border position, color and size on the image itself:

```
use SimonHamp\TheOg\BorderPosition;

$image = new Image;
$image->border(BorderPosition::Top, 'pink', 10);
```

The available border positions are:

- `BorderPosition::All` - All 4 edges will be bordered
- `BorderPosition::Bottom` - The bottom edge will be bordered
- `BorderPosition::Left` - The left edge will be bordered
- `BorderPosition::Right` - The right edge will be bordered
- `BorderPosition::None` - No edges will be bordered
- `BorderPosition::Top` - The top edge will be bordered
- `BorderPosition::X` - Combines `BorderPosition::Top` and `BorderPosition::Bottom`
- `BorderPosition::Y` - Combines `BorderPosition::Left` and `BorderPosition::Right`

#### Removing default borders

[](#removing-default-borders)

You can remove the default border from the image by chaining the `border()` method with the `position` argument set to `BorderPosition::None`:

```
$image = new Image;
$image->border(BorderPosition::None);
```

### Themes

[](#themes)

Themes set the colors, fonts, and styles for your image. There are currently 2 themes available: `Light` and `Dark`.

The default theme is `Light`.

You can set the theme on your image at any point before it's rendered:

```
use SimonHamp\TheOg\Theme;

$image = new Image;
$image->theme(Theme::Dark);
```

#### Creating themes

[](#creating-themes)

Themes are simple classes that implement the [`Theme` interface](https://github.com/simonhamp/the-og/blob/main/src/Interfaces/Theme.php).

However, you can create your own theme most easily by simply instantiating the [`Theme` class](https://github.com/simonhamp/the-og/blob/main/src/Theme/Theme.php):

```
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);
```

#### Fonts

[](#fonts)

Currently, there are 2 fonts available (each with 4 variants):

- [`Inter`](https://github.com/simonhamp/the-og/blob/main/src/Theme/Fonts/Inter.php)
- [`RobotoSlab`](https://github.com/simonhamp/the-og/blob/main/src/Theme/Fonts/Inter.php)

If you think a particular font will make sense added to the core of this package, please consider [contributing](#contributing) and open a Pull Request.

#### Custom fonts

[](#custom-fonts)

You can load custom fonts by creating a class that implements the [`Font` interface](https://github.com/simonhamp/the-og/blob/main/src/Interfaces/Font.php):

```
use SimonHamp\TheOg\Interfaces\Font;

class CustomFont implements Font
{
    public function path(): string
    {
        return '/path/to/your/font/source/file.ttf';
    }
}
```

Then you can load this font when defining your theme:

```
$font = new CustomFont;

$theme = new Theme(
    baseFont: $font,
);
```

#### Custom background images

[](#custom-background-images)

If the built-in background patterns don't tickle your fancy, you can load your own simply by instantiating the [`Background` class](https://github.com/simonhamp/the-og/blob/main/src/Theme/Background.php):

```
use SimonHamp\TheOg\Theme\Background;

$background = new Background('/path/to/your/image.png');
```

Then you can pass the background to your custom theme, or directly to your image:

```
$theme = new Theme(
    background: $background,
);

$image = (new Image)->theme($theme);

// Or

$image->background($background);
```

If you want more customization of the background, you may create your own background classes that implement the [`Background` interface](https://github.com/simonhamp/the-og/blob/main/src/Interfaces/Background.php).

#### Overriding theme settings

[](#overriding-theme-settings)

You can override some theme settings, such as the accent color, background and background color, without having to create a whole new theme.

```
$image = new Image;
$image->backgroundColor('seagreen')
    ->background($customBackground);
```

### Layouts

[](#layouts)

While themes govern the *colors* and *styles* used within your images, layouts govern the *size of your images* and the *size* and *position* of the image's elements (text blocks, other images etc.), called **features**.

Different layouts provide different features.

There are currently 3 layouts:

- [`Standard`](https://github.com/simonhamp/the-og/blob/main/src/Layout/Layouts/Standard.php)
- [`GitHubBasic`](https://github.com/simonhamp/the-og/blob/main/src/Layout/Layouts/GitHubBasic.php)
- [`TwoUp`](https://github.com/simonhamp/the-og/blob/main/src/Layout/Layouts/TwoUp.php)

The default layout is `Standard`.

More layouts are coming.

#### Creating layouts

[](#creating-layouts)

Layouts are simple classes with some basic settings and `features()` method to define all of your image's features.

Each layout class must implement the [`Layout` interface](https://github.com/simonhamp/the-og/blob/main/src/Interfaces/Layout.php)

[Take a look at the Standard layout](https://github.com/simonhamp/the-og/blob/main/src/Layout/Layouts/Standard.php), or any of the other built-in layouts, as an example.

In it, you'll see the basic settings for the layout, such as the dimensions of the canvas, the border size and location, and any padding.

**All sizes are in pixels.**

#### Features

[](#features)

Features are the individual elements that make up your image, such as the Title, Description, URL etc.

**All layouts** support a background (which is always rendered first) and a border (which is always rendered last), so you do not normally need to define these as distinct features.

Beyond that, the features of the image are entirely defined by the Layout. The order in which they are defined determines their rendering order and, therefore, their layering.

Available built-in features:

- [`TextBox`](https://github.com/simonhamp/the-og/blob/main/src/Layout/TextBox.php)Allows you to render a constrained block of text. The size of the box serves to constrain the text; the final size of the box is determined by the length, font, size, and line height of the rendered text.
- [`PictureBox`](https://github.com/simonhamp/the-og/blob/main/src/Layout/PictureBox.php)Allows you to render an image.

[See the built-in layouts](https://github.com/simonhamp/the-og/tree/main/src/Layout/Layouts) for examples of how to use these features and add them to a layout.

#### Positioning features

[](#positioning-features)

Features can be positioned absolutely anywhere on the canvas or relatively to another feature on the canvas.

To use relative positioning, it's helpful to give your target feature a unique name, which is used when other features need to reference its final rendered position.

[See the built-in layouts](https://github.com/simonhamp/the-og/tree/main/src/Layout/Layouts) for examples of how to position features.

#### Creating features

[](#creating-features)

All features must implement the [`Box` interface](https://github.com/simonhamp/the-og/blob/main/src/Interfaces/Box.php).

The key method of any feature is the `render()` method, which is responsible for rendering the feature onto the image. This method receives an instance of the underlying [`Intervention\Image\Image` class](https://github.com/Intervention/image/blob/develop/src/Image.php), allowing you to use Intervention's own modifiers directly, e.g.:

```
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);
  });
}
```

You should, however, extend the [`Box` class](https://github.com/simonhamp/the-og/blob/main/src/Layout/Box.php) as this provides a number of useful conveniences, especially if you want to use relative positioning.

Testing
-------

[](#testing)

The OG uses PHPUnit with [snapshot testing](https://github.com/spatie/phpunit-snapshot-assertions).

To run the integration tests, you need to install all Composer dependencies:

```
composer install
```

You will also need [Node.js](https://nodejs.org/en) (version 20 or above) and to install the NPM dependencies:

```
npm install
```

Once done, you can execute the tests:

```
./vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

I'd really appreciate and welcome any PRs to help improve this package!

Support
-------

[](#support)

All support is handled via [GitHub Issues](https://github.com/simonhamp/the-og/issues).

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE) for more details.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance61

Regular maintenance activity

Popularity50

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~105 days

Total

17

Last Release

243d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ab43d3432a80f0f41fe7015280f6024ff13fe8c2306cf114a1fbc91a4cd6f35?d=identicon)[simonhamp](/maintainers/simonhamp)

---

Top Contributors

[![simonhamp](https://avatars.githubusercontent.com/u/31628?v=4)](https://github.com/simonhamp "simonhamp (146 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (19 commits)")[![rico-vz](https://avatars.githubusercontent.com/u/107053109?v=4)](https://github.com/rico-vz "rico-vz (10 commits)")[![olivervogel](https://avatars.githubusercontent.com/u/884642?v=4)](https://github.com/olivervogel "olivervogel (3 commits)")[![nexxai](https://avatars.githubusercontent.com/u/4316564?v=4)](https://github.com/nexxai "nexxai (2 commits)")[![nicoverbruggen](https://avatars.githubusercontent.com/u/3715845?v=4)](https://github.com/nicoverbruggen "nicoverbruggen (1 commits)")[![intrepidws](https://avatars.githubusercontent.com/u/125735?v=4)](https://github.com/intrepidws "intrepidws (1 commits)")[![kevindierkx](https://avatars.githubusercontent.com/u/2406615?v=4)](https://github.com/kevindierkx "kevindierkx (1 commits)")[![imliam](https://avatars.githubusercontent.com/u/4326337?v=4)](https://github.com/imliam "imliam (1 commits)")

---

Tags

generatorimage-generationopengraph-imagesphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/simonhamp-the-og/health.svg)

```
[![Health](https://phpackages.com/badges/simonhamp-the-og/health.svg)](https://phpackages.com/packages/simonhamp-the-og)
```

###  Alternatives

[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k51.2M116](/packages/league-glide)[jenssegers/imagehash

Perceptual image hashing for PHP

2.1k2.2M5](/packages/jenssegers-imagehash)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[lasserafn/php-initial-avatar-generator

A package to generate avatars with initials for PHP

4374.2M13](/packages/lasserafn-php-initial-avatar-generator)[rtippin/messenger

Laravel messenger suite.

45035.8k4](/packages/rtippin-messenger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
