title: MP4 Video Thumbnail create using php GD
body: <p>I am using GD image library to upload videos but I can not create any thumbnail, is there any way to create mp4 video file thumbnail using php gb image library? </p>
  
  <p>this is my code; is it possible to entegrate ffmpeg ?</p>
  
  <pre><code>&lt;?php
  if(isset($_POST))
  {
  
  ############ Edit settings ##############
  $ThumbSquareSize        = 400; //Thumbnail will be 200x200
  $ThumbPrefix            = "thumb_"; //Normal thumb Prefix
  $DestinationDirectory   = 'uploads/'; //specify upload directory ends with / (slash)
  $Quality                = 90; //jpeg quality
  ##########################################
  
  //check if this is an ajax request
  if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
      die();
  }
  
  // check $_FILES['ImageFile'] not empty
  if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name']))
  {
          die('Something wrong with uploaded file, something missing!'); // output error when above checks fail.
  }
  
  // Random number will be added after image name
  $RandomNumber   = rand(0, 9999999999); 
  
  $ImageName      = str_replace(' ','-',strtolower($_FILES['ImageFile']['name'])); //get image name
  $ImageSize      = $_FILES['ImageFile']['size']; // get original image size
  $TempSrc        = $_FILES['ImageFile']['tmp_name']; // Temp name of image file stored in PHP tmp folder
  $ImageType      = $_FILES['ImageFile']['type']; //get file type, returns "image/png", image/jpeg, text/plain etc.
  
  //Let's check allowed $ImageType, we use PHP SWITCH statement here
  switch(strtolower($ImageType))
  {
      case 'video/mp4':
          break;
      default:
          die('Unsupported File!'); //output error and exit
  }
  
  //PHP getimagesize() function returns height/width from image file stored in PHP tmp folder.
  //Get first two values from image, width and height. 
  //list assign svalues to $CurWidth,$CurHeight
  list($CurWidth,$CurHeight)=getimagesize($TempSrc);
  
  //Get file extension from Image name, this will be added after random name
  $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
  $ImageExt = str_replace('.','',$ImageExt);
  
  //remove extension from filename
  $ImageName      = preg_replace("/\\.[^.\\s]{3,4}$/", "", $ImageName); 
  
  //Construct a new name with random number and extension.
  $NewImageName = $ImageName.'-'.$RandomNumber.'.'.$ImageExt;
  $pageurl = 'http://'.@$_SERVER['HTTP_HOST'].strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/').'';
  //set the Destination Image
  $thumb_DestRandImageName    = $DestinationDirectory.$ThumbPrefix.$NewImageName; //Thumbnail name with destination directory
  $DestRandImageName          = $DestinationDirectory.$NewImageName; // Image with destination directory
  
  //Resize image to Specified Size by calling resizeImage function.
  if(move_uploaded_file($_FILES['ImageFile']['tmp_name'], $DestinationDirectory.$NewImageName ))
  {
      //Create a square Thumbnail right after, this time we are using cropImage() function
      if(!resizeImage($CurWidth,$CurHeight,$ThumbSquareSize,$thumb_DestRandImageName,$Quality,$ImageType))
          {
              echo 'Error Creating thumbnail';
          }
      /*
      We have succesfully resized and created thumbnail image
      We can now output image to user's browser or store information in the database
      */
  $variable = &lt;&lt;&lt;XYZ
  &lt;div class="kingimgupload"&gt;
  &lt;iframe src="$pageurl/uploads/$NewImageName" alt="Resized Image"&gt;&lt;/iframe&gt;
  &lt;img src="$pageurl/uploads/$ThumbPrefix$NewImageName" alt="Resized Image"&gt;
  &lt;/div&gt;
  XYZ;
  echo $variable;
      /*
      // Insert info into database table!
      mysql_query("INSERT INTO myImageTable (ImageName, ThumbName, ImgPath)
      VALUES ($DestRandImageName, $thumb_DestRandImageName, 'uploads/')");
      */
  
  }else{
      die('Resize Error'); //output error
  }
  }
  
  
  // This function will proportionally resize image 
  function         resizeImage($CurWidth,$CurHeight,$MaxSize,$DestFolder,$SrcImage,$Quality,$ImageType)
  {
  //Check Image size is not 0
  if($CurWidth &lt;= 0 || $CurHeight &lt;= 0) 
  {
      return false;
  }
  
  //Construct a proportional size of new image
  $ImageScale         = min($MaxSize/$CurWidth, $MaxSize/$CurWidth); 
  $NewWidth           = ceil($ImageScale*$CurWidth);
  $NewHeight          = ceil($ImageScale*$CurHeight);
  $NewCanves          = imagecreatetruecolor($NewWidth, $NewHeight);
  
  // Resize Image
  if(imagecopyresampled($NewCanves, $SrcImage,0, 0, 0, 0, $NewWidth, $NewHeight, $CurWidth, $CurHeight))
  {
      switch(strtolower($ImageType))
      {
          case 'video/mp4':
              imagepng($NewCanves,$DestFolder);
              break;
          default:
              return false;
      }
  //Destroy image, frees memory   
  if(is_resource($NewCanves)) {imagedestroy($NewCanves);} 
  return true;
  }
  
  }
  </code></pre>