PHP Image Scaling Implementation method

Source: Internet
Author: User
Tags image png

  This article mainly introduces the PHP image scaling implementation method, the need for friends can refer to the following

PHP Basic Exercise-image scaling:       Code as follows: <?php    /**     * Image zoom.    /    function Imagezoom ($filename, $w, $h) {       /Arguments meaning * *        /* $filename: The source of the name * */        * $w: Want get the I Mage ' s width */       /* $h: You want get the Imgage ' s height */        $arr = GetImageSize ($filename);         $SRC _w = $arr [0];         $SRC _h = $arr [1];         $SRC _t = $arr [2];        /*1 = gif,2 = jpg,3 = png,4 = swf,5 = psd,6 = bmp,7 = TIFF (Intel byte order) = TIFF (Motorola byte order), 9 = jpc,10 = jp2,11 = jpx,12 = jb2,13 = SWC, = iff,15 = wbmp,16 = xbm*/        $SRC _m = $ Arr[' MIME '];           $SRC _img = Imagecreatefromjpeg ($filename);           if (($w/$src _w) > ($h/$src _h)) {            $bili = $h/$src _h;       &NB Sp else {            $bili = $w/$src _h;        }         $DST _w = $src _w * $bili;         $DST _h = $src _h * $bili;         $DST _img = Imagecreatetruecolor ($dst _w, $dst _h);           imagecopyresampled ($dst _img, $src _img, 0, 0, 0, 0, $dst _w, $dst _h, $src _w, $src _h);           header ("content-type:{$src _m}");           switch ($src _t) {            Case 1:     &NBSP ;           $imgout = "Imagegif";                 break;             Case 2:                 $imgout = "image JPEG ";         &nbsp       break;             Case 3:                 $imgout = "image PNG ";                 break;             default:                 echo "the type Was wrong! ";                 break;        }           $DST _filename = "S_". $filename;         $imgout ($dst _img, $dst _filename);           Imagedestroy ($dst _img);    }     $filename = ' gg.jpg ';     Imagezoom ($filename, 100, 200);       Core:<1> Note how scaling is achieved, although the resulting picture may be somewhat different from what is expected, but at least the scaling is guaranteed.   <2> type of control.  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.