$ W? $ Resizewidth = $ w: $ resizewidth = 400; // The width of the generated image. $ H? $ Resizeheight = $ h: $ resizeheight = 400; // The height of the generated image. 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 "; ?> |