PHPackages                             mpyw/opengraph - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mpyw/opengraph

Abandoned → [fusonic/opengraph](/?search=fusonic%2Fopengraph)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

mpyw/opengraph
==============

PHP library for consuming and publishing Open Graph resources.

v0.1.4(5y ago)43.8kMITPHPPHP ^7.2 || ^8.0

Since Jul 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mpyw/opengraph)[ Packagist](https://packagist.org/packages/mpyw/opengraph)[ Docs](https://github.com/mpyw/opengraph)[ RSS](/packages/mpyw-opengraph/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (4)Versions (6)Used By (0)

mpyw/opengraph
==============

[](#mpywopengraph)

[![Build Status](https://github.com/mpyw/opengraph/actions/workflows/ci.yml/badge.svg)](https://github.com/mpyw/opengraph/actions) [![Coverage Status](https://camo.githubusercontent.com/132e9e6f16d611ef42b880970cd8d6e5ebe53120ac5214ef8b9b7974f72b6478/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7079772f6f70656e67726170682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mpyw/opengraph?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/2f27da18c881530eae79391408914248a42cbfe1022ee7fdb62ff57f2ced57e1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d7079772f6f70656e67726170682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mpyw/opengraph/?branch=master)

A simple library to read Open Graph data from the web and generate HTML code to publish your own Open Graph objects. A fallback mode enables you to read data from websites that do not implement the Open Graph protocol.

Using this library you can easily retrieve stuff like meta data, video information from YouTube or Vimeo or image information from Flickr without using site-specific APIs since they all implement the Open Graph protocol.

See [ogp.me](http://ogp.me) for information on the Open Graph protocol.

Requirements
------------

[](#requirements)

- PHP `^7.3 || ^8.0`
- [symfony/css-selector](https://github.com/symfony/CssSelector): `^4.1`
- [symfony/dom-crawler](https://github.com/symfony/DomCrawler): `^4.1`

Installing
----------

[](#installing)

```
composer require mpyw/opengraph

```

Usage
-----

[](#usage)

### Retrieve Open Graph data from a URL

[](#retrieve-open-graph-data-from-a-url)

```
use Mpyw\OpenGraph\Consumer;

$consumer = new Consumer();
$object = $consumer->loadHtml(file_get_contents('http://www.youtube.com/watch?v=P422jZg50X4'));

// Basic information of the object
echo 'Title: ' . $object->title;                // Getting started with Facebook Open Graph
echo 'Site name: ' . $object->siteName;         // YouTube
echo 'Description: ' . $object->description;    // Originally recorded at the Facebook World ...
echo 'Canonical URL: ' . $object->url;          // http://www.youtube.com/watch?v=P422jZg50X4

// Images
$image = $object->images[0];
echo 'Image[0] URL: ' . $image->url             // https://i1.ytimg.com/vi/P422jZg50X4/maxresdefault.jpg
echo 'Image[0] height: ' . $image->height       // null (May return height in pixels on other pages)
echo 'Image[0] width: ' . $image->width         // null (May return width in pixels on other pages)

// Videos
$video = $object->videos[0];
echo 'Video URL: ' . $video->url                // http://www.youtube.com/v/P422jZg50X4?version=3&autohide=1
echo 'Video height: ' . $video->height          // 1080
echo 'Video width: ' . $video->width            // 1920
echo 'Video type: ' . $video->type              // application/x-shockwave-flash
```

*There are some more properties but these are the basic and most commonly used ones.*

### Publish own Open Graph data

[](#publish-own-open-graph-data)

```
use Mpyw\OpenGraph\Elements\Image;
use Mpyw\OpenGraph\Elements\Video;
use Mpyw\OpenGraph\Publisher;
use Mpyw\OpenGraph\Objects\Website;

$publisher = new Publisher();
$object = new Website();

// Basic information of the object
$object->title = 'Getting started with Facebook Open Graph';
$object->siteName = 'YouTube';
$object->description = 'Originally recorded at the Facebook World ...'
$object->url = 'http://www.youtube.com/watch?v=P422jZg50X4';

// Images
$image = new Image('https://i1.ytimg.com/vi/P422jZg50X4/maxresdefault.jpg');
$object->images[] = $image;

// Videos
$video = new Video('http://www.youtube.com/v/P422jZg50X4?version=3&autohide=1');
$video->height = 1080;
$video->width = 1920;
$video->type = 'application/x-shockwave-flash';
$object->videos[] = $video;

// Generate HTML code
echo $publisher->generateHtml($object);
//
//
//
//
//
//
//
//
//
```

*HTML code is formatted just for displaying purposes. You may choose between HTML5/XHTML output using the `$publisher->doctype` property.*

Running tests
-------------

[](#running-tests)

You can run the test suite with the following command:

```
phpunit --bootstrap tests/bootstrap.php .
```

License
-------

[](#license)

This library is licensed under the MIT license.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 59.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 ~181 days

Total

5

Last Release

1833d ago

PHP version history (2 changes)v0.1.0PHP ^7.2

v0.1.4PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1351893?v=4)[mpyw](/maintainers/mpyw)[@mpyw](https://github.com/mpyw)

---

Top Contributors

[![mburtscher](https://avatars.githubusercontent.com/u/229567?v=4)](https://github.com/mburtscher "mburtscher (38 commits)")[![mpyw](https://avatars.githubusercontent.com/u/1351893?v=4)](https://github.com/mpyw "mpyw (18 commits)")[![benallfree](https://avatars.githubusercontent.com/u/1068356?v=4)](https://github.com/benallfree "benallfree (1 commits)")[![DaveyBrown](https://avatars.githubusercontent.com/u/116117574?v=4)](https://github.com/DaveyBrown "DaveyBrown (1 commits)")[![hexium310](https://avatars.githubusercontent.com/u/10758173?v=4)](https://github.com/hexium310 "hexium310 (1 commits)")[![ingoldsby](https://avatars.githubusercontent.com/u/26500496?v=4)](https://github.com/ingoldsby "ingoldsby (1 commits)")[![manavo](https://avatars.githubusercontent.com/u/259487?v=4)](https://github.com/manavo "manavo (1 commits)")[![adamwych](https://avatars.githubusercontent.com/u/6526954?v=4)](https://github.com/adamwych "adamwych (1 commits)")[![mrbase](https://avatars.githubusercontent.com/u/304661?v=4)](https://github.com/mrbase "mrbase (1 commits)")[![amrelnaggar](https://avatars.githubusercontent.com/u/4163277?v=4)](https://github.com/amrelnaggar "amrelnaggar (1 commits)")

---

Tags

ogpogp-metaphpopengraphogp

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mpyw-opengraph/health.svg)

```
[![Health](https://phpackages.com/badges/mpyw-opengraph/health.svg)](https://phpackages.com/packages/mpyw-opengraph)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[spatie/crawler

Crawl all internal links found on a website

2.8k18.5M67](/packages/spatie-crawler)[blackfire/player

A powerful web crawler and web scraper with Blackfire support

49617.1k](/packages/blackfire-player)[drupal/drupal-extension

Drupal extension for Behat

22215.7M173](/packages/drupal-drupal-extension)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

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