头像

php缩放图片代码

2018-04-13 09:27:09 浏览()   来源:http://www.phpdaima.com//jsfx-43.html   评论 ( 0 )   

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


标签: php
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...