title: PHP GD resizing transparent image giving black border
body: <p>I am trying to downsize some transparents images in PHP with GD, and whenever I do, there is a weird black-ish border that is added around it.</p>
  
  <p><strong>Before</strong>
  <img src="https://i.stack.imgur.com/GJR5S.png" alt="before"></p>
  
  <p><strong>After</strong>
  <img src="https://i.stack.imgur.com/W3JDy.png" alt="enter image description here"></p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>&lt;?php
      $image = imagecreatefromstring(file_get_contents('logo.png'));
      $width = imagesx($image);
      $height = imagesy($image);
  
      $newWidth = $width - 1;
      $newHeight = $height - 1;
      $output = imagecreatetruecolor($newWidth, $newHeight);
      imagecolortransparent($output, imagecolorallocatealpha($output, 0, 0, 0, 127));
      imagealphablending($output, false);
      imagesavealpha($output, true);
      imagecopyresampled($output, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
  
      header('Content-Type: image/png');
      imagepng($output);
  ?&gt;
  </code></pre>
  
  <p>It seems that if I change the code for the new dimensions to be the same as the old (removing the <code>- 1</code>), no black borders appear. So the resize is causing the problem.</p>
  
  <p>Does anyone have an idea what might be wrong?</p>
  
  <p><em>Edit:</em> I just realized it only happens with <a href="http://php.net/manual/en/function.imagecopyresampled.php" rel="noreferrer"><code>imagecopyresampled</code></a> and not <a href="http://php.net/manual/en/function.imagecopyresized.php" rel="noreferrer"><code>imagecopyresized</code></a>. However, <code>imagecopyresampled</code> gives a far better visual effect and I'd like to make it work if possible.</p>