title: Select PHP's Image resizing algorithm
body: <p>The function <a href="https://www.php.net/manual/fr/function.imagecopyresampled.php" rel="nofollow noreferrer">imagecopyresampled</a> is useful to generate a thumbnail or resize images, while keeping aspect ratio:</p>
  <pre><code>$fn = $_FILES['data']['tmp_name'];
  $size = getimagesize($fn);
  $width = $size[0];
  $height = $size[1];
  $ratio = $width / $height;
  if ($ratio &gt; 1 &amp;&amp; $size[0] &gt; 500) { $width = 500; $height = 500 / $ratio; }
  else { if ($ratio &lt;= 1 &amp;&amp; $size[1] &gt; 500) { $width = 500 * $ratio; $height = 500; }}
  $src = imagecreatefromstring(file_get_contents($fn));
  $dst = imagecreatetruecolor($width, $height);
  imagecopyresampled($dst, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
  imagedestroy($src);
  imagejpeg($dst, 'test.jpg');
  imagedestroy($dst);
  </code></pre>
  <p><strong>How can I select the resizing algorithm used by PHP?</strong><br>
  <em>Note: as stated <a href="https://stackoverflow.com/q/41729409/1422096">in this question</a>, setting <code>imagesetinterpolation($dst, IMG_BILINEAR_FIXED);</code> or such things doesn't seem to work.</em></p>
  <hr />
  <p>According to tests I did (in another language), &quot;bilinear resizing&quot; sometimes gives better result than bicubic, and sometimes it's the contrary (depends if it's downsizing or upsizing).</p>
  <p><a href="https://i.stack.imgur.com/x8Yoj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x8Yoj.jpg" alt="" /></a><br />
  <sub>(source: <a href="https://www.dpchallenge.com/tutorial/8/images/resize_largematrix1.jpg" rel="nofollow noreferrer">dpchallenge.com</a>)</sub></p>