title: How can I convert all images to jpg?
body: <p>I have script:</p>
  
  <pre><code>&lt;?php
  
  include('db.php');
  session_start();
  $session_id = '1'; // User session id
  $path = "uploads/";
  
  $valid_formats = array("jpg", "png", "gif", "bmp", "jpeg");
  if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
      $name = $_FILES['photoimg']['name'];
      $size = $_FILES['photoimg']['size'];
      if (strlen($name)) {
          list($txt, $ext) = explode(".", $name);
          if (in_array($ext, $valid_formats)) {
              if ($size &lt; (1024 * 1024)) { // Image size max 1 MB
                  $actual_image_name = time() . $session_id . "." . $ext;
                  $tmp = $_FILES['photoimg']['tmp_name'];
                  if (move_uploaded_file($tmp, $path . $actual_image_name)) {
                      mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
                      echo "&lt;img src='uploads/" . $actual_image_name . "' class='preview'&gt;";
                  } else {
                      echo "failed";
                  }
              } else {
                  echo "Image file size max 1 MB";
              }
          } else {
              echo "Invalid file format..";
          }
      } else {
          echo "Please select image..!";
      }
      exit;
  }
  
  ?&gt;
  </code></pre>
  
  <p>Is possible convert all images (png, gif etc) to jpg with 100% quality? If yes, how? I would like allow to upload png and gif, but this script should convert this files to jpg. Is possible this with PHP?</p>