| ? $w? $resizewidth = $w: $resizewidth =400;//to generate the width of the picture $h? $resizeheight = $h: $resizeheight =400;//The height of the picture function Resizeimage ($im, $maxwidth, $maxheight, $name) { $width = Imagesx ($im); $height = Imagesy ($im); if ($maxwidth && $width > $maxwidth) | | ($maxheight && $height > $maxheight)) { if ($maxwidth && $width > $maxwidth) { $widthratio = $maxwidth/$width; $resizewidth =true; } if ($maxheight && $height > $maxheight) { $heightratio = $maxheight/$height; $resizeheight =true; } if ($resizewidth && $resizeheight) { if ($widthratio < $heightratio) { $ratio = $widthratio; }else{ $ratio = $heightratio; } }elseif ($resizewidth) { $ratio = $widthratio; }elseif ($resizeheight) { $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if (function_exists ("imagecopyresampled")) { $newim = Imagecreatetruecolor ($newwidth, $newheight); Imagecopyresampled ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = Imagecreate ($newwidth, $newheight); Imagecopyresized ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } Imagejpeg ($newim, $name); Imagedestroy ($newim); }else{ Imagejpeg ($im, $name); } } if ($_files[' uploadfile '] [' size ']) { if ($_files[' uploadfile '] [' type '] = = "Image/pjpeg") { $im = Imagecreatefromjpeg ($_files[' uploadfile '] [' tmp_name ']); }elseif ($_files[' uploadfile '] [' type '] = = "Image/x-png") { $im = imagecreatefrompng ($_files[' uploadfile '] [' tmp_name ']); }elseif ($_files[' uploadfile '] [' type '] = = "Image/gif") { $im = imagecreatefromgif ($_files[' uploadfile '] [' tmp_name ']); } if ($im) { if (file_exists (' bbs.jpg ')) { Unlink (' bbs.jpg '); } Resizeimage ($im, $resizewidth, $resizeheight, ' bbs.jpg '); Imagedestroy ($im);
} } $uploadfile = "Www.111cn.net.jpg"; ?> |