PHPackages                             simexis/embed - 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. simexis/embed

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

simexis/embed
=============

PHP library to retrieve page info using oembed, opengraph, etc

1.4.3(10y ago)29.0k4[1 PRs](https://github.com/jooorooo/embed/pulls)3MITPHPPHP &gt;=5.5.9

Since Oct 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jooorooo/embed)[ Packagist](https://packagist.org/packages/simexis/embed)[ Docs](https://github.com/oscarotero/Embed)[ RSS](/packages/simexis-embed/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (9)Used By (3)

\# Embed

PHP library to get information from any web page (using oembed, opengraph, twitter-cards, scrapping the html, etc). It's compatible with any web service (youtube, vimeo, flickr, instagram, etc) and has adapters to some sites like (archive.org, github, facebook, etc).

Requirements:

- PHP 5.4+
- Curl library installed

Usage
-----

[](#usage)

```
//Load library (if you don't have composer or any psr-4 compatible loader):
include('src/autoloader.php');

//Load any url:
$info = Embed\Embed::create('https://www.youtube.com/watch?v=PP1xn5wHtxE');

//Get content info

$info->title; //The page title
$info->description; //The page description
$info->url; //The canonical url
$info->type; //The page type (link, video, image, rich)

$info->images; //List of all images found in the page
$info->image; //The image choosen as main image
$info->imageWidth; //The width of the main image
$info->imageHeight; //The height of the main image

$info->code; //The code to embed the image, video, etc
$info->width; //The width of the embed code
$info->height; //The height of the embed code
$info->aspectRatio; //The aspect ratio (width/height)

$info->authorName; //The (video/article/image/whatever) author
$info->authorUrl; //The author url

$info->providerName; //The provider name of the page (youtube, twitter, instagram, etc)
$info->providerUrl; //The provider url
$info->providerIcons; //All provider icons found in the page
$info->providerIcon; //The icon choosen as main icon

$info->publishedDate; //The (video/article/image/whatever) published date
```

Customization
-------------

[](#customization)

You can set some options using an array as second argument. In this array you can configure the adapters, providers, resolvers, etc.

### The adapter

[](#the-adapter)

The adapter is the class that get all information of the page from the providers and choose the best result for each value. For example, a page can provide multiple titles from opengraph, twitter cards, oembed, the `` html element, etc, so the adapter get all this titles and choose the best one.

Embed has an generic adapter called "Webpage" to use in any web but has also some specific adapters for sites like archive.org, facebook, google, github, spotify, etc, that provides information using their own apis, or have any other special issue.

You can configure these adapters and even create your own adapter, that must implement the `Embed\Adapters\AdapterInterface`.

The available options for the adapters are:

- minImageWidth (int): Minimal image width used to choose the main image
- minImageHeight (int): Minimal image height used to choose the main image
- imagesBlacklist (array): Images that you don't want to be used. Could be plain text or [Url](https://github.com/oscarotero/Embed/blob/master/src/Url.php) match pattern.
- getBiggerImage (bool): Choose the bigger image as the main image (instead the first found, that usually is the most relevant).
- getBiggerIcon (bool): The same than getBiggerImage but used to choose the main icon

```
$config = [
	'adapter' => [
		'class' => 'MyCustomClass', //Your custom adapter

		'config' => [
			'minImageWidth' => 16,
            'minImageHeight' => 16,
            'imagesBlacklist' => null,
            'getBiggerImage' => false,
            'getBiggerIcon' => false,
		]
    ]
];
```

### The providers

[](#the-providers)

The providers get the data from different sources. Each source has it's own provider. For example, there is a provider for open graph, other for twitter cards, for oembed, html, etc. The providers that receive options are:

#### oembed

[](#oembed)

Used to get data from oembed api if it's available. It accepts two options:

- parameters (array): Extra query parameters to send with the oembed request
- embedlyKey (string): If it's defined and the page has not its own oembed service, use the embedly api.

#### html

[](#html)

Used to get data directly from the html code of the page:

- maxImages (int): Max number of images fetched from the html code (searching for the `` elements). By default is -1 (no limit). Use 0 to no get images.

#### facebook:

[](#facebook)

This provider is used only for facebook pages, to get information from the [graph api](https://developers.facebook.com/docs/graph-api):

- key (string): the access token used to get info from pages that are not public

#### soundcloud:

[](#soundcloud)

Used only for soundcloud pages, to get information using its api.

- key (string): to get info from soundcloud API.

```
$config = [
    'providers' => [
        'oembed' => [
            'parameters' => [],
            'embedlyKey' => null
        ],
        'html' => [
            'maxImages' => -1
        ],
        'facebook' => [
            'key' => 'our-access-token'
        ]
    ]
];
```

### The request resolver

[](#the-request-resolver)

Embed uses the `Embed\RequestResolvers\Curl` class to resolve all requests using the curl library. You can set options to the curl request or use your custom resolver creating a class implementing the `Embed\RequestResolvers\RequestResolverInterface`.

The resolver configuration is defined under the "resolver" key and it has two options:

- class: Your custom class name if you want to use your own implementation
- config: The options passed to the class. If you use the default curl class, the config are the same than the [curl\_setopt PHP function](http://php.net/manual/en/function.curl-setopt.php)

```
// CURL
$config = [
    'resolver' => [
        'class' => 'Embed\\RequestResolvers\\Curl' // The default resolver used

        'config' => [
            CURLOPT_MAXREDIRS => 20,
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_ENCODING => '',
            CURLOPT_AUTOREFERER => true,
            CURLOPT_USERAGENT => 'Embed PHP Library',
            CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
        ]
    ]
];

// Guzzle (5.x)
$config = [
    'resolver' => [
        'class' => 'Embed\\RequestResolvers\\Guzzle5', // Guzzle5 resolver used

        'config' => [
            // optional: if you need to use your custom Guzzle instance
            'client' => $myGuzzleClient,
        ]
    ]
];
```

### Image info

[](#image-info)

To check the images and get their mimetype and dimmensions, we have the class `Embed\ImageInfo\Curl`. This class uses curl to make request, get the first bytes to get the image type and dimmensions and close the connection. So the image wont be downloaded entirely, just until the downloaded data is enought to get this information.

Like the resolver class, you can provide your own image class (it must implement the `Embed\ImageInfo\ImageInfoInterface`) and/or change the configuration. The available options are the same:

- class: Your custom class name if you want to use your own implementation
- config: The options passed to the class. If you use the default curl class, the config are the same than the [curl\_setopt PHP function](http://php.net/manual/en/function.curl-setopt.php)

```
$config = [
    'image' => [
        'class' => 'Embed\\ImageInfo\\Curl' //The default imageInfo used

        'config' => [
            CURLOPT_MAXREDIRS => 20,
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_ENCODING => '',
            CURLOPT_AUTOREFERER => true,
            CURLOPT_USERAGENT => 'Embed PHP Library',
            CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
        ]
    ]
];
```

### Example

[](#example)

```
$config = [
	'adapter' => [
		'config' => [
			'minImageWidth' => 16,
            'minImageHeight' => 16,
            'imagesBlacklist' => [
                'http://example.com/full/path/to/image.jpg',
                'http?://test.*/*.png/',
                '*/bad_image.gif'
            ]
		]
	],
    'providers' => [
        'html' => [
            'maxImages' => 3
        ]
    ],
    'resolver' => [
        'config' => [
            CURLOPT_USERAGENT => 'My spider',
            CURLOPT_MAXREDIRS => 3
        ]
    ]
	'image' => [
		'class' => 'App\\MyImageInfoClass'
	]
];
```

Do you need help?
-----------------

[](#do-you-need-help)

I can help you in HackHands:

Contributors
------------

[](#contributors)

-  (creator and maintainer)
-
-

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

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 ~0 days

Total

8

Last Release

3925d ago

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

1.2PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94e45e0fc8056daeec3bc285ca4befdbaf5064a57f29bd9d93a9459afab9a28?d=identicon)[jooorooo](/maintainers/jooorooo)

---

Tags

embedlyembedopengraphoembedtwitter cardssimexis

### Embed Badge

![Health badge](/badges/simexis-embed/health.svg)

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

###  Alternatives

[embed/embed

PHP library to retrieve page info using oembed, opengraph, etc

2.2k11.9M117](/packages/embed-embed)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[oat-sa/tao-core

TAO core extension

66143.7k124](/packages/oat-sa-tao-core)

PHPackages © 2026

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