vanessia_1999 0 Junior Poster in Training

I am trying to make the image proportionate so that it does not look pixelated. Some of my image look nice but others look pixelated. Is there a way or a code that I can use to make all my thumbnail images proportional from the original image or something like that?

<?php
function getThumb($Original)
{
   if (!$Original['name'])
   {
      //no image supplied, use default
      $TempName = "images/noimage.jpg";
      $TempFile = fopen($TempName, "r");
      $thumbnail = fread($TempFile, fileSize($TempName));
   } else
   {
      //get image
      $Picture =  file_get_contents($Original['tmp_name']);      //create image
      $SourceImage = imagecreatefromstring($Picture);
      if (!$SourceImage)
      {
         //not a valid image
        echo "Not a valid image\n";
        $TempName = "images/noimage.jpg";
        $TempFile = fopen($TempName, "r");
        $thumbnail = fread($TempFile, fileSize($TempName));
      } else
      {
         //create thumbnail
         $thumbWidth = 150;
         $width = imageSX($SourceImage);
         $height = imageSY($SourceImage);
         $new_width = $thumbWidth;
         $new_height = floor( $height * ( $thumbWidth / $width ) );
         
         $newThumb = imagecreatetruecolor($new_width, $new_height);         //resize image to 80 x 60
         $result = imagecopyresampled($newThumb, $SourceImage, 
                                      0, 0, 0, 0,
                                      $new_width, $new_height, $width, $height);         //move image to variable
         ob_start();
         imageJPEG($newThumb);
         $thumbnail = ob_get_contents();
         ob_end_clean();
      }
   }
   return $thumbnail;
}?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.