src/Readability.php
public function getMainImage()
    {
        $imgUrl = false;

        if ($this->getImage() !== null) {
            $imgUrl = $this->getImage();
        }

        if (!$imgUrl) {
            foreach ($this->dom->getElementsByTagName('link') as $link) {
                /** @var \DOMElement $link */
                /*
                 * Check for the rel attribute, then check if the rel attribute is either img_src or image_src, and
                 * finally check for the existence of the href attribute, which should hold the image url.
                 */
                if ($link->hasAttribute('rel') && ($link->getAttribute('rel') === 'img_src' || $link->getAttribute('rel') === 'image_src') && $link->hasAttribute('href')) {
                    $imgUrl = $link->getAttribute('href');
                    break;
                }
            }
        }

        if (!empty($imgUrl) && $this->configuration->getFixRelativeURLs()) {
            $this->setImage($this->toAbsoluteURI($imgUrl));
        }
    }
public function getMainImage()
    {
        $imgUrl = false;

        if ($this->getImage() !== null) {
            $imgUrl = $this->getImage();
        }

        if (!$imgUrl) {
            foreach ($this->dom->getElementsByTagName('link') as $link) {
                /** @var \DOMElement $link */
                /*
                 * Check for the rel attribute, then check if the rel attribute is either img_src or image_src, and
                 * finally check for the existence of the href attribute, which should hold the image url.
                 */
                if ($link->hasAttribute('rel') && ($link->getAttribute('rel') === 'img_src' || $link->getAttribute('rel') === 'image_src') && $link->hasAttribute('href')) {
                    $imgUrl = $link->getAttribute('href');
                    break;
                }
            }
        }

        if (!empty($imgUrl) && $this->configuration->getFixRelativeURLs()) {
            $this->setImage($this->toAbsoluteURI($imgUrl));
        }
    }
public function getMainImage ( ) { $ imgUrl = false ; if ( $ this -> getImage ( ) !== null ) { $ imgUrl = $ this -> getImage ( ) ; } if ( ! $ imgUrl ) { foreach ( $ this -> dom -> getElementsByTagName ( 'link' ) as $ link ) { /** @var \DOMElement $link */ /*
                 * Check for the rel attribute, then check if the rel attribute is either img_src or image_src, and
                 * finally check for the existence of the href attribute, which should hold the image url.
                 */ if ( $ link -> hasAttribute ( 'rel' ) && ( $ link -> getAttribute ( 'rel' ) === 'img_src' || $ link -> getAttribute ( 'rel' ) === 'image_src' ) && $ link -> hasAttribute ( 'href' ) ) { $ imgUrl = $ link -> getAttribute ( 'href' ) ; break ; } } } if ( ! empty ( $ imgUrl ) && $ this -> configuration -> getFixRelativeURLs ( ) ) { $ this -> setImage ( $ this -> toAbsoluteURI ( $ imgUrl ) ) ; } }
Tries to get the main article image. Will only update the metadata if the getMetadata function couldn't
find a correct image.
Tries to get the main article image . Will only update the metadata if the getMetadata function couldn t find a correct image .