php 缩略图实现函数代码
作者:bea
array getimagesize ( string $filename [, array &$imageinfo ] ) 取得图像大小 resource imagecreatetruecolor ( int $x_size , int $y_size ) 新建一个真彩色图像 resource imagecreatefromjpeg ( string $filename ) 从 JPEG 文件或 URL 新建一图像 bool imagecopyresized ( r
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 格式将图像输出到浏览器或文件
代码如下:
<?php
/*
Created by <A href="http://www.cnphp.info">http://www.cnphp.info</A>
*/
// 文件及缩放尺寸
//$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);
?>
有用 | 无用
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 格式将图像输出到浏览器或文件
代码如下:
<?php
/*
Created by <A href="http://www.cnphp.info">http://www.cnphp.info</A>
*/
// 文件及缩放尺寸
//$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);
?>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- php设计模式 Proxy (代理模式)
- php设计模式 Composite (组合模式)
- php设计模式 State (状态模式)
- php设计模式 Bridge (桥接模式)
- php设计模式 Chain Of Responsibility (职责链模式)
- php设计模式 FlyWeight (享元模式)
- php设计模式 Mediator (中介者模式)
- php设计模式 Prototype (原型模式)代码
- PHP如何解决网站大流量与高并发的问题
- session在PHP大型web应用中的使用
- php URL跳转代码 减少外链
- php session安全问题分析
- 使用PHP实现二分查找算法代码分享
- PHP求最大子序列和的算法实现
- php中转义mysql语句的实现代码
- 把1316这个数表示成两个数的和,其中一个为13的倍数,另一个是11的倍数,求这两个数。
- php中对2个数组相加的函数
- php判断输入不超过mysql的varchar字段的长度范围
- PHP array操作10个小技巧分享