php缩放图片代码
php缩放图片代码 [代码片段(19行)]
<?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验证码实现代码
- 下一篇:php 利用PHPEXCEL导出excel文件
收藏文章
精彩图集
精彩文章