Giter VIP home page Giter VIP logo

icon-scraper's Introduction

Get Apple Touch Icons and Favicon from a Website

Build Status Scrutinizer Code Quality

Overview

This library returns an array of apple-touch-icon and the favicon for a given url, sorted by width.

Requirements

PHP 5.4+

Composer

Use Composer by adding the following lines in your composer.json:

"require": {
    "mpclarkson/icon-scraper": "dev-master"
},

Usage

    require_once('vendor/autoload.php');

    $scraper = new \Mpclarkson\IconScraper\Scraper();

    $icons = $scraper->get('http://hilenium.com');

    foreach($icons as $icon) {
        $icon->getType(); //Returns favicon or apple-touch-icon
        $icon->getHref(); //Returns a url
        $icon->getSize(); //Returns an array of integers, or empty for favicons
        $icon->getWidth(); //Integer or null
        $icon->getHeight(); //Integer or null
    }

    //$icons looks like this:

    Array
    (
        [0] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => favicon
                [href:Mpclarkson\IconScraper\Icon:private] => http://d1nhhppd50p5r.cloudfront.net/favicon.ico?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                    )

            )

        [1] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => http://d1nhhppd50p5r.cloudfront.net/css/96113be.css?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                    )
            )

        [2] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => https://d1nhhppd50p5r.cloudfront.net/icon57.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 57
                        [1] => 57
                    )
            )

        [3] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => http://d1nhhppd50p5r.cloudfront.net/icon72.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 72
                        [1] => 72
                    )
            )

        [4] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => https://d1nhhppd50p5r.cloudfront.net/icon76.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 76
                        [1] => 76
                    )

            )

        [5] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => https://d1nhhppd50p5r.cloudfront.net/icon114.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 114
                        [1] => 114
                    )

            )

        [6] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => https://d1nhhppd50p5r.cloudfront.net/icon120.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 120
                        [1] => 120
                    )

            )

        [7] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => https://d1nhhppd50p5r.cloudfront.net/icon144.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 144
                        [1] => 144
                    )

            )

        [8] => Mpclarkson\IconScraper\Icon Object
            (
                [type:Mpclarkson\IconScraper\Icon:private] => apple-touch-icon
                [href:Mpclarkson\IconScraper\Icon:private] => http://d1nhhppd50p5r.cloudfront.net/icon152.png?1433897130
                [size:Mpclarkson\IconScraper\Icon:private] => Array
                    (
                        [0] => 152
                        [1] => 152
                    )

            )
    )

Todos

  • More tests
  • Improve code style

Credits

This library is significant fork of this library by Arthur Hoaro. Key changes include:

  • Returns an array of icons, rather than just the favicon
  • Icons returned as Icon objects which include the following properties: type, href and size, and getters for width and height
  • No caching
  • PSR-4

Thanks goes to Hilenium.

icon-scraper's People

Contributors

akalongman avatar digitalbase avatar mpclarkson avatar scrutinizer-auto-fixer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.