<?php |
// 指定文件路径和缩放比例 |
$filename = 'test.jpg' ; |
$percent = 0.5; |
// 指定头文件Content typezhi值 |
header( 'Content-type: image/jpeg' ); |
// 获取图片的宽高 |
list( $width , $height ) = getimagesize ( $filename ); |
$newwidth = $width * $percent ; |
$newheight = $height * $percent ; |
// 创建一个图片。接收参数分别为宽高,返回生成的资源句柄 |
$thumb = imagecreatetruecolor( $newwidth , $newheight ); |
//获取源文件资源句柄。接收参数为图片路径,返回句柄 |
$source = imagecreatefromjpeg( $filename ); |
// 将源文件剪切全部域并缩小放到目标图片上。前两个为资源句柄 |
imagecopyresampled( $thumb , $source , 0, 0, 0, 0, $newwidth , $newheight , $width , $height ); |
// 输出给浏览器 |
imagejpeg( $thumb ); |
?> |