[PHP]picture Zoom
Sunday on August 7th, 2005Life
picture zoom
& lt;?phpIf (isset ($_ GET [& quot;filename"])) {$srcfile = $_ GET [& quot;filename"]//echo $srcfileResizeimage ($srcfile, 100)}/** Image zooming* $srcfile source image* $rate zoom ratio, which is reduced by half by default, or specific width pixel value* for example: resizeimage (& quot;zt32.gif",".1")* for example: resizeimage (& quot;zt32.gif","250")* Note: when calling, put the result of the function directly in the SRC attribute in the IMG tag of the HTML file.,/Function resizeimage ($srcfile,$rate=.5) {$size=getimagesize ($srcfile)Switch ($size [2]) {Case 1:$img=imagecreatefromgif ($srcfile)BreakCase 2:$img=imagecreatefromjpeg ($srcfile)BreakCase 3:$img=imagecreatefrompng ($srcfile)Break}//width and height of the source image$srcw=imagesx ($img)$srch=imagesy ($img)//the width and height of the destination pictureIf ($size [0] & lt;= $rate | | $size [1] & lt;= $rate) {$dstw=$srcw$dsth=$srch} else {If ($rate & lt;= 1) {$dstw=floor ($srcw*$rate)$dsth=floor ($srch*$rate)} else {$dstw=$rate$rate = $rate/$srcw$dsth=floor ($srch*$rate)}}//echo & quot;$dstw,$dsth,$srcw,$srch & quot//create a new true color image$im=imagecreatetruecolor ($dstw,$dsth)$black=imagecolorallocate ($im,255255255)Imagefilledrectangle ($im,0,0,$dstw,$dsth,$black)Imagecopyresized ($im,$img,0,0,0,0,$dstw,$dsth,$srcw,$srch)//output the image to a browser or file in JPEG formatImagejpeg ($im)//release the pictureImagedestroy ($im)Imagedestroy ($img)}? & gt
this only applies to thumbnails above version 4.0.6
[from: kingerq]
Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/PHP-picture-Zoom.htm