title: Creating tumbnails with PHP for differnet formats
body: <p>So i a did this script which create tumbnails on the fly with php and it is working fine, but these files that i am createing tumbnails for are being uploaded from the user. Which i have enough validation to know which type of image it is being uploaded. The allowed once are (<strong>JPG PNG GIF</strong>) no i have created this script above.</p>
  
  <pre><code>if (pathinfo($fileName,PATHINFO_EXTENSION) == 'png'){
                  $img = imagecreatefrompng($basePath.'/'.$fileName);
                  $width = imagesx($img);
                  $height = imagesx($img);
  
                  //Calculateing tumbnails size
                  $newWidth = 100;
                  $newHeight = floor($height*(100/$width));
  
                  //Create a new tempoary image
                  $tmpImage = imagecreatetruecolor($newWidth,$newHeight);
  
                  imagecopyresized($tmpImage,$img,0,0,0,0,$newWidth,$newHeight,$width,$height);
  
                  imagepng($tmpImage,$pathToTumb.'/'.$fileName);
              }
              if (pathinfo($fileName,PATHINFO_EXTENSION) == 'jpg'){
                  $img = imagecreatefromjpeg($basePath.'/'.$fileName);
                  $width = imagesx($img);
                  $height = imagesx($img);
  
                  //Calculateing tumbnails size
                  $newWidth = 100;
                  $newHeight = floor($height*(100/$width));
  
                  //Create a new tempoary image
                  $tmpImage = imagecreatetruecolor($newWidth,$newHeight);
  
                  imagecopyresized($tmpImage,$img,0,0,0,0,$newWidth,$newHeight,$width,$height);
  
                  imagejpeg($tmpImage,$pathToTumb.'/'.$fileName);
              }
              if(pathinfo($fileName,PATHINFO_EXTENSION) == 'gif'){
                  $img = imagecreatefromgif($basePath.'/'.$fileName);
                  $width = imagesx($img);
                  $height = imagesx($img);
  
                  //Calculateing tumbnails size
                  $newWidth = 100;
                  $newHeight = floor($height*(100/$width));
  
                  //Create a new tempoary image
                  $tmpImage = imagecreatetruecolor($newWidth,$newHeight);
  
                  imagecopyresized($tmpImage,$img,0,0,0,0,$newWidth,$newHeight,$width,$height);
  
                  imagegif($tmpImage,$pathToTumb.'/'.$fileName);
              }
  </code></pre>
  
  <p>I find that very repetitive is there a different way to do this for different formats?</p>
  
  <p>Also I want would to if it is even possible to do this when the image does not  have an extension for example if the name of the file is just test instead of test.jpg</p>