服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - PHP教程 - php 缩略图实现函数代码

php 缩略图实现函数代码

2019-12-01 12:17PHP教程网 PHP教程

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 格式将图像输出到浏览器或文件 

复制代码代码如下:


<?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); 
?> 

延伸 · 阅读

精彩推荐