开发者

how to automatic crop to the right place of image with php

开发者 https://www.devze.com 2022-12-15 12:15 出处:网络
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) {

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 "ima开发者_JAVA百科ge/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 http://www.wajdani.com/pind/wajdanians/avatars/FA5RRS10N10DOXK5-1_810JL54S8W22T10A416346_104115209606932_100000253614165_97589_5729392_n.jpg

and this is the result after cropped

not found http://www.wajdani.com/pind/wajdanians/avatars/thumb_FA5RRS10N10DOXK5-1_810JL54S8W22T10A416346_104115209606932_100000253614165_97589_5729392_n.jpg

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号