title: Performance of fpdf image in php7.4
body: <p>We use fpdf to create pdf documents. With the Image function we place an image on a pdf. In version php7.3 an image that we used a lot took 0,25 sec to place, to our surprise in version php7.4 it went up to 0,7 sec. We started looking for the exact spot this caused. It turned out to be the following routine in the Image function:</p>
  <p>first</p>
  <pre><code>// Read image data block
  $data .= $this-&gt;_readstream($f,$n);
  </code></pre>
  <p>later on</p>
  <pre><code>$len = 4*$w;
  for($i=0;$i&lt;$h;$i++)
  {
      $pos = (1+$len)*$i;
      $color .= $data[$pos];
      $alpha .= $data[$pos];
      $line = substr($data,$pos+1,$len);
      $color .= preg_replace('/(.{3})./s','$1',$line);
      $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
  }
  </code></pre>
  <p>For an image of w x h of let's say 1200 x 600 pixels quite a bit happens here. The performance issues exist in the for-loop.</p>
  <p>Our questions are then</p>
  <ol>
  <li>Why is this a lot slower in php7.4 than php7.3 ?</li>
  <li>Exactly which statement causes this and why?</li>
  <li>What can be done about this?</li>
  </ol>
  <p>Thank you in advance</p>