Based on the custom target graph height, the source graph is cropped and scaled by the target graph aspect.
Incoming parameters:
$source _path String Source map path
$target _width integer Target graph width
$target _height integer target graph height
The source map supports Mimetype:image/gif, Image/jpeg, Image/png.
function Imagecropper ($source _path, $target _width, $target _height) {$source _info = getimagesize ($source _path); $ Source_width = $source _info[0]; $source _height = $source _info[1]; $source _mime = $source _info[' mime ']; $source _ratio = $s ource_height/$source _width, $target _ratio = $target _height/$target _width;//Source graph too high if ($source _ratio > $target _ratio) {$cropped _width = $source _width; $cropped _height = $source _width * $target _ratio; $source _x = 0; $source _y = ($source _heigh T $cropped _height)/2;} Source map too wide ElseIf ($source _ratio < $target _ratio) {$cropped _width = $source _height/$target _ratio; $cropped _height = $sour ce_height; $source _x = ($source _width-$cropped _width)/2; $source _y = 0;} SOURCE Graph Moderate else{$cropped _width = $source _width; $cropped _height = $source _height; $source _x = 0; $source _y = 0;} Switch ($source _mime) {case ' image/gif ': $source _image = imagecreatefromgif ($source _path); Break;case ' Image/jpeg ': $ Source_image = Imagecreatefromjpeg ($source _path); Break;case ' image/png ': $source _imagE = imagecreatefrompng ($source _path); Break;default:return False;break;} $target _image = Imagecreatetruecolor ($target _width, $target _height); $cropped _image = Imagecreatetruecolor ($cropped _ width, $cropped _height);//Crop Imagecopy ($cropped _image, $source _image, 0, 0, $source _x, $source _y, $cropped _width, $ Cropped_height); Zoom imagecopyresampled ($target _image, $cropped _image, 0, 0, 0, 0, $target _width, $target _height, $cropped _width, $ Cropped_height); header (' content-type:image/jpeg '); imagejpeg ($target _image); Imagedestroy ($source _image); Imagedestroy ($target _image); Imagedestroy ($cropped _image);}
http://www.bkjia.com/PHPjc/739133.html www.bkjia.com true http://www.bkjia.com/PHPjc/739133.html techarticle According to the custom target graph height width, according to the target graph aspect than cropping, the scale source graph. Incoming parameters: $source _pathstring Source map path $target _widthinteger target width $target _heightinteger ...