title: PHP GD library resize photo
body: <p>I am attempting to create thumbnails of photos using PHP's GD library.</p>
  
  <p>Here are the steps I am taking. </p>
  
  <ol>
  <li>Create GD Image resource.</li>
  <li>Get height and width of image</li>
  <li>create a blank gd image resource at 100 pixels high by appropriate width</li>
  <li>copy resource image to blank gd image resource and save both images</li>
  </ol>
  
  <p>Here is my code:</p>
  
  <pre><code>private function getExtension($filename) {
      $position=strrpos($filename, '.');
      $extension = strtolower(substr($filename, $position+1));
      if ($extension == "jpg") {
          $extension = "jpeg";
      }
  
      return $extension;
  }
  
  public function saveImage($parameters) {
      $extension=$this-&gt;getExtension($parameters['filename']);
      $createImageFunc="imagecreatefrom".$extension;
      $imgResource=$createImageFunc(SITE_PATH."tmp/{$parameters['filename']}");
      $width=imagesx($imgResource);
      $height=imagesy($imgResource);
      $ratio=$height/$width;
      $thumbnail=imagecreatetruecolor(100, 100*$ratio);
  
      imagecopyresized($thumbnail, $imgResource, 0, 0, 0, 0, 100*$ratio, 100, $width, $height);
  
      $imgResult=imagejpeg($imgResource, SITE_PATH."images/{$parameters['galleryName']}/{$parameters['filename']}");
      $thumbResult=imagejpeg($thumbnail, SITE_PATH."images/{$parameters['galleryName']}/thumbnails/{$parameters['filename']}");
  
  }
  </code></pre>
  
  <p>The images are saving, but the copy is not working, there is empty black space in the thumbnail picture.</p>
  
  <p>This is the original Image:
  <img src="https://i.stack.imgur.com/MwKq0.jpg" alt="enter image description here"></p>
  
  <p>This is the image saved again with gd:
  <img src="https://i.stack.imgur.com/YeNah.jpg" alt="enter image description here"></p>
  
  <p>This is the thumbnail:
  <img src="https://i.stack.imgur.com/TpQCY.jpg" alt="enter image description here"></p>
  
  <p>I've like quadruple checked imagecopyresize and from what I understand of it all the values in the code should be correct.</p>
  
  <p>Here is what php.net has for the values: </p>
  
  <pre><code>bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
  </code></pre>
  
  <p>Any one got any ideas?</p>