PHPackages                             rych/thumbnail-finder - 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. rych/thumbnail-finder

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

rych/thumbnail-finder
=====================

Simple library for discovering thumbnail image from a URL.

v0.1.0(12y ago)1141[1 issues](https://github.com/rchouinard/thumbnail-finder/issues)[1 PRs](https://github.com/rchouinard/thumbnail-finder/pulls)MITPHPPHP &gt;= 5.3.0

Since Feb 1Pushed 9y agoCompare

[ Source](https://github.com/rchouinard/thumbnail-finder)[ Packagist](https://packagist.org/packages/rych/thumbnail-finder)[ RSS](/packages/rych-thumbnail-finder/feed)WikiDiscussions master Synced 3d ago

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

Thumbnail Finder
================

[](#thumbnail-finder)

Quick project I threw together as part of a larger project. While writing a content aggregator I found I needed a way to discover a thumbnail for the linked content.

This library only discovers the "best" image URL to use. Actually downloading and cropping/resizing/otherwise processing the image is out of scope.

How does it work?
-----------------

[](#how-does-it-work)

The library simply scans an HTML document for an image suitable for use as a thumbnail and return the URL to that image. Suitable images are discovered via OpenGraph metadata, the older Facebook image\_src microformat, and by crawling the document for img tags and using a simple algorithm for finding the "most interesting" image.

When the library has to resort to crawling the linked images, it downloads only as much of each image as is required to extract the image width and height. The library discards very small images and images which are much wider than tall or taller than wide. The remaining images are compared based on area, and the largest image is returned.

This library currently uses Symfony's Dom Crawler and CSS Selector components to work its magic. The Imagick extension for PHP is also required for extracting width and height from partial image downloads.

Usage
-----

[](#usage)

Very simple:

```
