PHP Tutorial by the specified size and so on to release into a thumbnail image upload
/**
* *
* Equal to zoom
* @param unknown_type $srcImage Source picture path
* @param unknown_type $toFile target picture path
* @param unknown_type $maxWidth Maximum width
* @param unknown_type $maxHeight Maximum height
* @param unknown_type $imgQuality picture quality
* @return Unknown
*/
Function Resize ($srcImage, $toFile, $maxWidth =, $maxHeight = +, $imgQuality =100)
{
List ($width, $ Height, $type, $attr) = getimagesize ($srcImage);
if ($width < $maxWidth | | $height < $maxHeight) return;
Switch ($type) {
Case 1: $img = Imagecreatefromgif ($srcImage), break,
Case 2: $img = Imagecreatefromjpeg ($src Image); Break
Case 3: $img = Imagecreatefrompng ($srcImage);
}
$scale = min ($maxWidth/$width, $maxHeight/$height);//Find bloom ratio
if ($scale < 1) {
$newWidth = floor ($scale * $width);
$newHeight = Floor ($scale * $height);
$NEWIMG = Imagecreatetruecolor ($newWidth, $newHeight);
imagecopyresampled ($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$newName = "";
$toFile = Preg_replace ("/(. gif|. Jpg|. Jpeg|. PNG)/I "," ", $toFile);
Switch ($type) {
Case 1:if (Imagegif ($newImg, "$toFile $newname.gif", $imgQuality))
Return "$newName. gif"; Break
Case 2:if (imagejpeg ($newImg, "$toFile $newname.jpg", $imgQuality))
Return "$newName. jpg"; Break
Case 3:if (Imagepng ($newImg, "$toFile $newname.png", $imgQuality))
Return "$newName. png"; Break
Default:if (imagejpeg ($newImg, "$toFile $newname.jpg", $imgQuality))
Return "$newName. jpg"; Break
}
Imagedestroy ($NEWIMG);
}
Imagedestroy ($IMG);
return false;
}
http://www.bkjia.com/PHPjc/444947.html www.bkjia.com true http://www.bkjia.com/PHPjc/444947.html techarticle PHP Tutorial by the specified size and so on to release into the image thumbnail/** * * * * Zoom * @param unknown_type $srcImage Source Picture path * @param unknown_type $toFile destination picture path ...