php圖片縮放實現方法

來源:互聯網
上載者:User

 這篇文章主要介紹了php圖片縮放實現方法,需要的朋友可以參考下

php基礎練習--圖片縮放:   代碼如下:<?php    /**    * image zoom.    */    function imageZoom($filename, $w, $h) {        /* Arguments meaning */        /* $filename: the source of the name */        /* $w: you want get the image'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;        } 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:                $imgout = "imagegif";                break;            case 2:                $imgout = "imagejpeg";                break;            case 3:                $imgout = "imagepng";                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);   核心:<1>注意縮放比例如何得到,雖然這樣得到的圖片可能會與預想的有點差別,但是最起碼保證了縮放比例。    <2>類型的控制。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.