tags:

views:

106

answers:

1

how can i crop the image with php with its exact to the face of user in image....here is my 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;
}

and here is call of this function

$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);

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

Pic not found

and this is the result after cropped

not found

please let me know what is actually the problem....

+2  A: 

You would need to detect the image via OCR alike software.

You had to read all pixels and construct the possibility in % if this is a part of the user's pic.

Better let them choose a thumbnail ;)

maxedmelon
you mean to let user to choose their own thumbnail area from their big one....??
Web Worm
How else would you want to define the facial area? It'll be at least ten years until there will be worthwhile automatic face recognition in PHP.
Pekka