PHP: get largest image - performance issue
<p>The below code finds all the images on a given website and returns the largest, BUT it is terribly slow. Can anyone help? Thanks!</p>

<pre><code>$largest = 0;
$images = array();

reg_match_all('/(img|src)\=(\"|\')[^\"\'\&gt;]+/i', $html, $media);
unset($html);

$data=preg_replace('/(img|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);
foreach($data as $imgUrl) {
$info = pathinfo($imgUrl);

if (isset($info['extension'])) {
    if (($info['extension'] == 'jpg') ||
        ($info['extension'] == 'jpeg') ||
        ($info['extension'] == 'gif') ||
        ($info['extension'] == 'png')) {

        array_push($images, $imgUrl);
        $imgUrl = $this-&gt;rel2abs($imgUrl, $this-&gt;url);
        list($width, $height, $type, $attr) = getimagesize($imgUrl);
        $size = $width * $height;

        if ($size &gt; $largest) {
            $this-&gt;image = $imgUrl;
            $largest = $size;
        }
    }
}
</code></pre>
