Customizable PHP thumbnail generation program (requires GD library support)

xiaoxiao2021-04-07  335

Classic PHP thumbnail generation program, based on GD library, can specify a generated path and generate a wide high detail method of generating a target: Save the following code as a resize.php test in the PHP environment that supports the GD library.

$ 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 ($ NE WIM, $ IM, 0, 0, 0, 0, $ NewWidth, $ Newheight, $ Width, $ HEIGHT);} ImageJPEG ($ NEWIM, $ UPLOADDIR. $ Name. "" .jpg "); ImageDestroy ($ NEWIM); Else {ImageJPEG ($ IM, $ UPLOADDIR. $ Name. ".jpg");}}} f ($ _ files ['Image'] ['size']) {= f ($ _ files ['Image'] ['Type '] == "image / pjpeg") {$ = imagecreatefromjpeg ($ _ files [' image '] [' TMP_NAME ']);} elseif ($ _ files [' Image '] [' type '] == "Image / X-PNG ") {$ = imagecreateFromPng ($ _ files ['image'] ['tmp_name']);} elseif ($ _ files ['image'] ['

转载请注明原文地址:https://www.9cbs.com/read-132425.html

New Post(0)