• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php图片缩放实现方法_php实例

php 搞代码 4年前 (2022-01-25) 17次浏览 已收录 0个评论

php基础练习–图片缩放:

<?php<BR>    /**<BR>    * image zoom.<BR>    */<BR>    function imageZoom($filename, $w, $h) {<BR>        /* Arguments meaning */<BR>        /* $filename: the source of the name */<BR>        /* $w: you want get the image's width */<BR>        /* $h: you want get the imgage's height */<BR>        $arr = getimagesize($filename);<BR>        $src_w = $arr[0];<BR>        $src_h = $arr[1];<BR>        $src_t = $arr[2];<BR>        /*1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),<BR>= TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,<BR>= IFF,15 = WBMP,16 = XBM*/<BR>        $src_m = $arr['mime'];</P><P>        $src_img = imagecreatefromjpeg($filename);</P><P>        if (($w / $src_w) >($h / $src_h)) {<BR>            $bili = $h / $src_h;<BR>        } else {<BR>            $bili = $w / $src_h;<BR>        }<BR>        $dst_w = $src_w * $bili;<BR>        $dst_h = $src_h * $bili;<BR>        $dst_img = imagecreatetruecolor($dst_w, $dst_h);</P><P>        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);</P><P>        header("content-type:{$src_m}");</P><P>        switch ($src_t) {<BR>            case 1:<BR>                $imgout = "imagegif";<BR>                break;<BR>            case 2:<BR>                $imgout = "imagejpeg";<BR>                break;<BR>            case 3:<BR>                $imgout = "imagepng";<BR>                break;<BR>            default:<BR>                echo "The type was wrong!";<BR>                break;<BR>        }</P><P>        $dst_filename = "s_".$filename;<BR>        $imgout($dst_img, $dst_filename<span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea>);</P><P>        imagedestroy($dst_img);<BR>    }<BR>    $filename = 'gg.jpg';<BR>    imageZoom($filename, 100, 200);<BR>

核心:注意缩放比例如何得到,虽然这样得到的图片可能会与预想的有点差别,但是最起码保证了缩放比例。

   类型的控制。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php图片缩放实现方法_php实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址