how to automatic crop to the right place of image with php
<p>how can i crop the image with php with its exact to the face of user in image....here is my code....</p>

<pre><code>function resizeImage($image,$width,$height,$scale) {
    list($imagewidth, $imageheight, $imageType) = getimagesize($image);
    $imageType = image_type_to_mime_type($imageType);
    $newImageWidth = ceil($width * $scale);
    $newImageHeight = ceil($height * $scale);
    $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
    switch($imageType) {
        case "image/gif":
            $source=imagecreatefromgif($image); 
            break;
        case "image/pjpeg":
        case "image/jpeg":
        case "image/jpg":
            $source=imagecreatefromjpeg($image); 
            break;
        case "image/png":
        case "image/x-png":
            $source=imagecreatefrompng($image); 
            break;
    }
    imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);

    switch($imageType) {
        case "image/gif":
            imagegif($newImage,$image); 
            break;
        case "image/pjpeg":
        case "image/jpeg":
        case "image/jpg":
            imagejpeg($newImage,$image,90); 
            break;
        case "image/png":
        case "image/x-png":
            imagepng($newImage,$image);  
            break;
    }

    chmod($image, 0777);
    return $image;
}
</code></pre>

<p>and here is call of this function</p>

<pre><code>$wwidth = getWidth($new_small_image);
            $hheight = getHeight($new_small_image);
            $x1 = $wwidth/2;            
            $y1 = $hheight/2;
            $x2 = 0;
            $y2 = 0;
            $w = 50;
            $h = 50;
            $scale = $thumb_width/$w;
            resizeThumbnailImage($new_small_image, $new_small_image,$w,$h,$x1,$y1,$scale);
</code></pre>

<p>but it is cropping exact center of the image, that is not right i want to crop the image to face of image e.g</p>

<p><img src="http://www.wajdani.com/pind/wajdanians/avatars/FA5RRS10N10DOXK5-1_810JL54S8W22T10A416346_104115209606932_100000253614165_97589_5729392_n.jpg" alt="Pic not found"></p>

<p>and this is the result after cropped</p>

<p><img src="http://www.wajdani.com/pind/wajdanians/avatars/thumb_FA5RRS10N10DOXK5-1_810JL54S8W22T10A416346_104115209606932_100000253614165_97589_5729392_n.jpg" alt="not found"></p>

<p>please let me know what is actually the problem....</p>
