title: Resize picture without losing quality
body: <p>I have to resize images with PHP.
  But... the quality is very, very bad !! (look at the picture)</p>
  
  <p>Here my code :</p>
  
  <pre><code>function _copyAndResizeImage($id, $wanted_width, $isAdvert=true) {
  // The file
  if ($isAdvert) {
      $filename = "../upload/images/advert/".$id."/1.jpg";
  } else {
      $filename = "../upload/images/user/".$id.".jpg";
  }
  
  list($width, $height) = getimagesize($filename);
  
  if ($width == 0) {
      $percent=1;
  } else {
      $percent = $wanted_width / $width;
  }
  
  // Content type
  header('Content-Type: image/jpeg');
  
  // Get new dimensions
  $new_width = $width * $percent;
  $new_height = $height * $percent;
  
  // Resample
  $image_p = imagecreatetruecolor($new_width, $new_height);
  $image = imagecreatefromjpeg($filename);
  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  
  // Output
  if ($isAdvert) {
      imagejpeg($image_p, '../upload/images/advert/'.$id.'/1-'.$wanted_width.'.jpg');
  } else {
      imagejpeg($image_p, '../upload/images/user/'.$id.'-'.$wanted_width.'.jpg');
  }
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/aloCs.jpg" alt="enter image description here"></p>
  
  <p>Have you got an idea ?
  Thanks</p>