PHPackages                             53ny4/og-image - 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. 53ny4/og-image

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

53ny4/og-image
==============

Generate Open Graph image for your website

2.2.3(8mo ago)1602MITPHPPHP ^8.2

Since Oct 23Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/53ny4/og-image)[ Packagist](https://packagist.org/packages/53ny4/og-image)[ RSS](/packages/53ny4-og-image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (25)Used By (0)

OG Image Generator
==================

[](#og-image-generator)

Table of Contents
=================

[](#table-of-contents)

- [OG Image Generator](#og-image-generator)
    - [Example](#example)
    - [📦 Installation](#-installation)
    - [⚙️ Requirements](#%EF%B8%8F-requirements)
    - [🚀 Features](#-features)
    - [🧱 Usage](#-usage)
    - [📝 License](#-license)

---

A simple and flexible PHP library for generating Open Graph (OG) (but really any type of) images with customizable backgrounds, text, and watermarks. Perfect for creating dynamic social media preview images for your website or application.

This project was inspired by my clients, each of them wanted to have a custom OG image for their website. One wanted to have a simple image with a quote, another wanted to have an avatar of the user displayed and so on. While there are projects like that and don't get me wrong, they are great, but they are not flexible enough for my needs.

On the other hand, Imagine/Imagine is a great library, but it has a bit of code to write to get the desired result.

Example
-------

[](#example)

---

[![Example](docs/images/example.png)](docs/images/example.png)

### Code for the above image:

[](#code-for-the-above-image)

```
$og = new OgImageGenerator();
$og->setBackgroundImage('src/assets/images/bg.png');
$og->createImage();

$text = (new TextElement())
    ->setText('OgImage')
    ->setFontSize(75)
    ->setFontColor('#ffffff')
    ->setFontPath('src/assets/fonts/BebasNeue-Regular.ttf')
    ->setBgOpacity(50)
    ->setMargin(50)
    ->setPosition('top', 'center');

$text2 = (new TextElement())
    ->setText('Hello World!')
    ->setFontSize(50)
    ->setFontColor('#ffffff')
    ->setFontPath('src/assets/fonts/BebasNeue-Regular.ttf')
    ->setBgColor('#000000')
    ->setBgOpacity(50)
    ->setPosition(470, 'center');

$text3 = (new TextElement())
    ->setText('Lorem ipsum dolor sit amet, consectetur adipiscing elit. ')
    ->setFontSize(25)
    ->setFontColor('#ffffff')
    ->setFontPath('src/assets/fonts/BebasNeue-Regular.ttf')
    ->setBgOpacity(50)
    ->setPosition(539, 'center');

$watermark = (new Watermark())
    ->setWatermarkPath('src/assets/images/watermark.png')
    ->setSize(100)
    ->setMargin(10)
    ->setPosition('bottom', 'right');

$og->addWatermark($watermark);
$og->addText($text);
$og->addText($text2);
$og->addText($text3);

$og->render();
```

📦 Installation
--------------

[](#-installation)

---

```
composer require 53ny4/og-image
```

⚙️ Requirements
---------------

[](#️-requirements)

---

- PHP ^8.2
- `imagine/imagine` (automatically installed)
- supports only `GD` driver

🚀 Features
----------

[](#-features)

---

- Add styled text to your image (font, size, color, opacity, alignment)
- Add background overlays for text
- Automatic text wrapping and line height adjustment
- Place elements using top/center/bottom and left/center/right positions
- Add watermarks with position and opacity options
- Fit and scale background images to fill the canvas

🧱 Usage
-------

[](#-usage)

---

```
require 'vendor/autoload.php';

use s3ny4\OgImage\OgImageGenerator;
use s3ny4\OgImage\TextElement;
use s3ny4\OgImage\Watermark;

// Create generator instance
$og = new OgImageGenerator(1200, 630);

// Add background image
$og->setBackgroundImage('path/to/background.jpg');

// Add text
$text = (new TextElement())
    ->setText('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam accumsan sed lacus venenatis eleifend. Aenean ipsum turpis, faucibus nec maximus sit amet, lobortis vel nisl. ')
    ->setPosition('center', 'center')
    ->setFontPath('src/assets/fonts/font.ttf')
    ->setFontSize(36)
    ->setFontColor('#ffffff')
    ->setBgOpacity(50)
    ->setBgColor('#ff0000');

$og->addText($text);

// Add watermark
$watermark = (new Watermark('src/assets/images/logo.png'))
    ->setPosition('top', 'center')
    ->setMargin(50)
    ->setSize(150)
    ->setOpacity(50);
$og->addWatermark($watermark);

// output image to the browser
$og->render();

// or save to file
// $og->render('og-image.png');
```

📝 License
---------

[](#-license)

---

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance59

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 55.4% 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 ~15 days

Recently: every ~32 days

Total

21

Last Release

260d ago

Major Versions

0.4.0 → 1.0.02024-10-27

1.6.1 → 2.0.02025-04-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/8077ee47bbeeb0d7f138d2255e25480c5e465b1d5933983874c71f89d0387809?d=identicon)[53ny4](/maintainers/53ny4)

---

Top Contributors

[![1337haxx0r](https://avatars.githubusercontent.com/u/1227760?v=4)](https://github.com/1337haxx0r "1337haxx0r (36 commits)")[![53ny4](https://avatars.githubusercontent.com/u/185612834?v=4)](https://github.com/53ny4 "53ny4 (29 commits)")

---

Tags

imageopen-graphog

### Embed Badge

![Health badge](/badges/53ny4-og-image/health.svg)

```
[![Health](https://phpackages.com/badges/53ny4-og-image/health.svg)](https://phpackages.com/packages/53ny4-og-image)
```

###  Alternatives

[liip/imagine-bundle

This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.

1.7k38.3M217](/packages/liip-imagine-bundle)[folklore/image

Image manipulation library for Laravel 5 based on Imagine and inspired by Croppa for easy url based manipulation

270248.2k5](/packages/folklore-image)[orchestra/imagine

Imagine (Wrapper) Component for Laravel

70207.0k3](/packages/orchestra-imagine)[media-alchemyst/media-alchemyst

An Object Oriented wrapper for easy multimedia conversion, based on Imagine, FFMpeg, SwfTools, Unoconv and other libs

65216.4k1](/packages/media-alchemyst-media-alchemyst)

PHPackages © 2026

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