• 技术文章 >php教程 >php手册

    php 缩略图实现函数代码_php入门_脚本之家

    2016-06-06 20:37:42原创431

    php 生成缩略图函数非常简单,只是调入了几个GD的系统函数,不过却很实用

    array getimagesize ( string $filename [, array &$imageinfo ] ) 取得图像大小
    resource imagecreatetruecolor ( int $x_size , int $y_size ) 新建一个真彩色图像
    resource imagecreatefromjpeg ( string $filename ) 从 JPEG 文件或 URL 新建一图像
    bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) 拷贝部分图像并调整大小
    bool imagejpeg ( resource $image [, string $filename [, int $quality ]] ) 以 JPEG 格式将图像输出到浏览器或文件
    代码如下:
    /*
    Created by http://www.cnphp.info
    */
    // 文件及缩放尺寸
    //$imgfile = 'smp.jpg';
    //$percent = 0.2;
    header('Content-type: image/jpeg');
    list($width, $height) = getimagesize($imgfile);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;
    $thumb = ImageCreateTrueColor($newwidth,$newheight);
    $source = imagecreatefromjpeg($imgfile);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    imagejpeg($thumb);
    ?>

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:缩略图
    上一篇:PHP和Mysqlweb应用开发核心技术 第1部分 Php基础-1 开始了解php 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • php批量添加数据与批量更新数据的实现方法,php添加数据• PHP代码:Http断点续传的实现例子• PHP5中Cookie与 Session使用详解• php实现文件下载更能介绍• php写的简易聊天室代码
    1/1

    PHP中文网