title: php GD Libraries ; how to detect if the image have more white or black before crop to avoid artifact
body: <p>Is it possible to detect if an image contains more white or more black...</p>
  
  <p>I have a working croping function but when I want to crop an image (in some cases) the result have artifacts</p>
  
  <p>Example 1 :</p>
  
  <ul>
  <li><p>Picture with more white ; <a href="https://i.stack.imgur.com/dPqQV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPqQV.jpg" alt="enter image description here"></a></p></li>
  <li><p>Give this reult when cropped <a href="https://i.stack.imgur.com/I3Jnl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I3Jnl.jpg" alt="enter image description here"></a></p></li>
  </ul>
  
  <p>Example 2 (ok) :</p>
  
  <ul>
  <li><p>Picture with more black : <a href="https://i.stack.imgur.com/mZTvG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mZTvG.jpg" alt="enter image description here"></a></p></li>
  <li><p>give ok result : <a href="https://i.stack.imgur.com/dVFlw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dVFlw.png" alt="enter image description here"></a></p></li>
  </ul>
  
  <p>The code</p>
  
  <pre><code>$newImage300 = imagecreatetruecolor($jFinalWidth,$jFinalHeight);
  $wcolor = imagecolorallocate($newImage300, 0, 0, 0);
  imagefill($newImage, 0, 0, $wcolor);
  imagecopyresampled ($newImage300, $newImage, 0, 0, 0, 0, $jFinalWidth, $jFinalHeight, $jWidth, $jHeight);
  
  // save image       
  imagejpeg($newImage,__path_to_new_saved_img___,70);
  </code></pre>
  
  <p>What kind of code could be added to avoid the artifact from example 1 ?</p>
  
  <p>Changing for grey it's worse...</p>
  
  <p>See the results :</p>
  
  <p><a href="https://i.stack.imgur.com/dPqQV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPqQV.jpg" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/I3Jnl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I3Jnl.jpg" alt="enter image description here"></a></p>