【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-9_25.php,希望本篇文章对您学习有所帮助。
<?php
//定义一个这是,指定要缩放的文件
$file = "large.png";
//定义一个变量,指定要缩放的比例
$percent = 0.5;
//使用getimagesize()函数,取得要缩放图片的大小,并使用list()绑定到变量
list($width,$height) = getimagesize($file);
//根据缩放比例,取得缩略图的宽度与高度
$twidth = $width*$percent;
$theight = $height*$percent;
//根据参数创建一个新图形,用于接收复制的文件
$dst = imagecreatetruecolor($twidth,$theight);
//根据PNG图形创建一个图形
$src = imagecreatefrompng($file);
//把$src文件中的内容复制,缩小后复制到目标文件
imagecopyresampled($dst,$src,0,0,0,0,$twidth,$theight,$width,$height);
//输出类型信息
header('Content-type: image/png');
//输出PNG文件
imagepng($dst);
//释放资源
imagedestroy($src);
imagedestroy($dst);
?>