title: Slow getimagesize
body: <p>I need to show multiple posts on my website. These posts are combined of internal and external posts. The external posts are periodically imported and saved in my DB using a cronjob.</p>
  
  <p>Before showing the posts I extract the text from all HTML. In addition I try to locate the first image contained in the post, continuing until I find an image which height &amp; width meets my requirements. (I only show a small version of the text, and one picture from the post as a teaser)</p>
  
  <p>For the purpose of finding the most suitable picture, I use getimagesize, but unfortunately this often creates PHP Execution time of several seconds!</p>
  
  <p>How can I speed up my function below? I'm desperate for tips and good tweaking methods!!</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>//extract text without tags from blog post
  $content = str_get_html("".$post_text."")-&gt;plaintext;
  
  $max_width = 475;
  $picture_id = 0;
  
  //fetch images from blog post
  foreach($html-&gt;find('img') as $e) {
  
  //get picture attributes
  list($width, $height, $type, $attr) = getimagesize((is_absolute_url($e-&gt;src) ? $e-&gt;src : $_SERVER['DOCUMENT_ROOT'].$e-&gt;src));
  
  //adjust image width &amp; height, so it's the size of the page
  $new_width = $max_width;
  $new_height = $new_width / $width * $height;
  
  //find percentage of current width versus max width
  $percentage = ($width / $max_width) * 100;
  
      //select picture for display and resizing if the picture is large enough (we don't want to stretch it too much)
      if($percentage &gt;= 60) {
  
          $e-&gt;width = $new_width;
          $e-&gt;height = $new_height;
  
          $picture = array('src' =&gt; $e-&gt;src, 'width' =&gt; $e-&gt;width, 'height' =&gt; $e-&gt;height);
  
          //stop after first picture is found :: we only need one per post
          if (++$picture_id == 1) break;
  
      }
  
  }
  </code></pre>