title: How to Improve image quality when resized as a thumbnail using PHP?
body: <p>I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image.</p>
  
  <p>And is there a better way to create thumbnails if so can you point me to a tutorial on how to create thumbnails using PHP.</p>
  
  <p>Here is the code below.</p>
  
  <pre><code>&lt;?php
  function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth)
  {
  $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
  $origWidth = imagesx($srcImg);
  $origHeight = imagesy($srcImg);
  
  $ratio = $origWidth / $thumbWidth;
  $thumbHeight = $origHeight / $ratio;
  
  $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
  imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
  
  imagejpeg($thumbImg, "$thumbDirectory/$imageName");
  }
  
  createThumbnail("images", "pic.jpg", "images/thumbs/", 180);
  
  ?&gt;
  </code></pre>