PHPackages                             le0m/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. le0m/opengraph

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

le0m/opengraph
==============

PHP library for consuming and publishing Open Graph resources.

1.1.0(6y ago)051MITPHPPHP ^5.4|^7.0

Since Jul 23Pushed 6y agoCompare

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

READMEChangelogDependencies (5)Versions (3)Used By (0)

fusonic/opengraph
=================

[](#fusonicopengraph)

[![Build Status](https://camo.githubusercontent.com/f377f0c98845dfe1957e0b0b9f65cf3630da4033bd6ba65bc7e324b32895bc30/68747470733a2f2f7472617669732d63692e6f72672f6675736f6e69632f6f70656e67726170682e706e67)](https://travis-ci.org/fusonic/opengraph)[![](https://camo.githubusercontent.com/d3f2826fa58a94d5987ec40db75e4bc592314a3c02c39d8de8775381c7250e31/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6675736f6e69632f6f70656e67726170682f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/fusonic/opengraph/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/5c68ea6190827f48c432fc9f527ebc25a8dc5f7af1ad488fdcfec17273f372c7/68747470733a2f2f706f7365722e707567782e6f72672f6675736f6e69632f6f70656e67726170682f646f776e6c6f6164732e706e67)](https://packagist.org/packages/fusonic/opengraph)

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 5.4 and up
- [fusonic/linq](https://github.com/fusonic/linq)
- [guzzlehttp/guzzle](https://github.com/guzzle/guzzle)
- [symfony/css-selector](https://github.com/symfony/CssSelector)
- [symfony/dom-crawler](https://github.com/symfony/DomCrawler)

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

[](#installation)

The most flexible installation method is using Composer: Simply create a composer.json file in the root of your project:

```
{
    "require": {
        "fusonic/opengraph": "@dev"
    }
}
```

Install composer and run install command:

```
curl -s http://getcomposer.org/installer | php
php composer.phar install
```

Once installed, include vendor/autoload.php in your script.

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

Usage
-----

[](#usage)

### Retrieve Open Graph data from a URL

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

```
use Fusonic\OpenGraph\Consumer;

$consumer = new Consumer();
$object = $consumer->loadUrl("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 Fusonic\OpenGraph\Elements\Image;
use Fusonic\OpenGraph\Elements\Video;
use Fusonic\OpenGraph\Publisher;
use Fusonic\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

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.5% 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 ~1763 days

Total

2

Last Release

2549d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

1.1.0PHP ^5.4|^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/36a1b89a62185411675b209cd97652abd29a4e98bd3e68cb5e402bee9ae883d6?d=identicon)[le0m](/maintainers/le0m)

---

Top Contributors

[![mburtscher](https://avatars.githubusercontent.com/u/229567?v=4)](https://github.com/mburtscher "mburtscher (38 commits)")[![benallfree](https://avatars.githubusercontent.com/u/1068356?v=4)](https://github.com/benallfree "benallfree (1 commits)")[![le0m](https://avatars.githubusercontent.com/u/10656716?v=4)](https://github.com/le0m "le0m (1 commits)")[![manavo](https://avatars.githubusercontent.com/u/259487?v=4)](https://github.com/manavo "manavo (1 commits)")[![mrbase](https://avatars.githubusercontent.com/u/304661?v=4)](https://github.com/mrbase "mrbase (1 commits)")

---

Tags

opengraph

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[ashallendesign/favicon-fetcher

A Laravel package for fetching website's favicons.

190272.4k3](/packages/ashallendesign-favicon-fetcher)[fusonic/opengraph

PHP library for consuming and publishing Open Graph resources.

104373.0k4](/packages/fusonic-opengraph)[visuellverstehen/statamic-classify

A useful helper to add CSS classes to all HTML tags generated by the bard editor.

20116.8k](/packages/visuellverstehen-statamic-classify)[jonom/silverstripe-share-care

Social media sharing previews and customisation for Silverstripe

2932.7k1](/packages/jonom-silverstripe-share-care)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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