Copy CodeThe code is as follows:
function Imageresize ($srcFile, $toW, $toH, $toFile = "")
{
if ($toFile = = "") {$toFile = $srcFile;}
$info = "";
$data = getimagesize ($srcFile, $info);
Switch ($data [2])
{
Case 1:
if (!function_exists ("Imagecreatefromgif")) {
echo "Your GD library cannot use GIF format pictures, please use JPEG or PNG format!" Return ";
Exit ();
}
$im = Imagecreatefromgif ($srcFile);
Break
Case 2:
if (!function_exists ("Imagecreatefromjpeg")) {
echo "Your GD library can not use JPEG format pictures, please use other format pictures!" Return ";
Exit ();
}
$im = Imagecreatefromjpeg ($srcFile);
Break
Case 3:
$im = Imagecreatefrompng ($srcFile);
Break
}
$srcW =imagesx ($im);
$srcH =imagesy ($im);
$toWH = $toW/$toH;
$srcWH = $srcW/$srcH;
if ($toWH <= $srcWH) {
$ftoW = $toW;
$ftoH = $ftoW * ($srcH/$srcW);
}
else{
$ftoH = $toH;
$ftoW = $ftoH * ($srcW/$srcH);
}
if ($srcW > $toW | | $srcH > $toH)
{
if (function_exists ("Imagecreatetruecolor")) {
@ $ni = Imagecreatetruecolor ($ftoW, $ftoH);
if ($ni) imagecopyresampled ($ni, $im, 0,0,0,0, $ftoW, $ftoH, $srcW, $srcH);
else{
$ni =imagecreate ($ftoW, $ftoH);
Imagecopyresized ($ni, $im, 0,0,0,0, $ftoW, $ftoH, $srcW, $srcH);
}
}else{
$ni =imagecreate ($ftoW, $ftoH);
Imagecopyresized ($ni, $im, 0,0,0,0, $ftoW, $ftoH, $srcW, $srcH);
}
if (function_exists (' imagejpeg ')) imagejpeg ($ni, $toFile);
Else Imagepng ($ni, $toFile);
Imagedestroy ($ni);
}
Imagedestroy ($im);
}
http://www.bkjia.com/PHPjc/322863.html www.bkjia.com true http://www.bkjia.com/PHPjc/322863.html techarticle Copy the code as follows: function imageresize ($srcFile, $toW, $toH, $toFile = "") {if ($toFile = = "") {$toFile = $srcFile;} $info = ""; $data = getimagesize ($srcFile, $info); Switch ($d ...