title: How to Find Image Type from New Image Created Via PHP
body: <pre><code>&lt;?php
  
  $server_root = $_SERVER['DOCUMENT_ROOT'];
  
  
  $auction = $_GET['auction'];
  $item = $_GET['item'];
  $dir = $_GET['dir'];
  $img = urldecode($_GET['img']);
  
  $image = explode('/',$img);
  //parse out the file name
  $folder = '/'.$image[3].'/';
  
  $file = $image[4];
  $image = $folder.$file;
  $imagePath = $server_root.$image;
  
  //set the correct direction
  if ($dir == 'ccw') {
      $degrees = 90;
  } else {
      $degrees = '270';
  }
  $source = imagecreatefromjpeg($imagePath);
  
  $rotate = imagerotate($source, $degrees, 0);
  
  
  //delete the old file
  unlink($imagePath);
  $newFile = 'img_'.$item.'_'.time().'.jpg';
  // $newFile = 'img_'.$item.'.jpg';
  
  $newFileName = $server_root.$folder.$newFile;
  
  
  imagejpeg($rotate, $imagePath);
  
  
  imagedestroy($source);
  imagedestroy($rotate);
  
  
  ?&gt;
  </code></pre>
  
  <p>I'm trying to grab the image type after using the above code snippet to rotate and save that rotated image. </p>
  
  <p>I tried using:</p>
  
  <pre><code>$typeString = null;
  $typeInt = exif_imagetype($newFilename);
  switch($typeInt) {
    case IMG_GIF:
      $typeString = 'image/gif';
      break;
    case IMG_JPG:
      $typeString = 'image/jpg';
      break;
    case IMG_JPEG:
      $typeString = 'image/jpeg';
      break;
    case IMG_PNG:
      $typeString = 'image/png';
      break;
    case IMG_WBMP:
      $typeString = 'image/wbmp';
      break;
    case IMG_XPM:
      $typeString = 'image/xpm';
      break;
    default:
      $typeString = 'unknown';
  }
  </code></pre>
  
  <p>But that kept outputting an error. So I'm not sure what is the best solution to grab the image type based on the above code. The reason I need the image type is to use a function I created to made 3 different sized images for that image and that function requires an image type, but I can't seem to figure out how to pull the image type using the above snippet.</p>