imagecopyresampled()改变图片大小后质量要比imagecopyresized()高。
php程序中改变图片大小的函数大多数人都想到用imagecopyresized(),不过经过测试比较发现,使用imagecopyresampled()改变的图片质量更高。
下面我们来看看两者的比较结果。
原图:
使用imagecopyresized()将图片缩小一半
代码:
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>
改变后的图片:
使用imagecopyresampled()将图片缩小一半
代码:
<?php
// The file
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
?>
改变后的图片:
可以看出,imagecopyresampled()改变图片大小后质量要比imagecopyresized()高。
最新文章
- wap
- Hibernate持久化类属性映射
- Centos下防火墙的设置
- logstash_agent.conf 语法注意事项
- 自定义textbox加入左右晃动效果
- MD5加密算法测试
- 《APUE》第四章笔记(1)
- 关于 submit 按钮的 onclick 验证事件,第一次验证失败,第二次 submit 按钮失效的原因解析
- webView的一些经验总结
- 产品在焊接时出现异常,尤其是尺寸较大的QFP芯片,焊接后出现虚焊、冷焊、假焊等问题?
- Linux SSL 双向认证 浅解
- java读取和写入txt文件
- python——杂货铺
- 1001 数组中和等于K的数对 1002 数塔取数问题 1003 阶乘后面0的数量 1004 n^n的末位数字 1009 数字1的数量
- Docker-Dockerfile及基本语法
- Python- - -函数目录
- python字典遍历的几种方法
- Appium移动自动化测试(一)----Appium的安装
- 【LeetCode】Binary Tree Upside Down
- SqlServer横向扩展负载均衡终极利器SqlServerProxy 不限功能永久免费
热门文章
- 【spring boot logback】日志使用自定义的logback-spring.xml文件后,application.properties中关于日志的相关配置还会起作用么
- 单页js文件访问数据库
- 移植MonkeyRunner的图片对照和获取子图功能的实现-UiAutomator/Robotium篇
- JavaScript实现网页元素的拖拽效果
- dom控制
- 【Excle数据透视表】如何移动数据透视表的位置
- 非常酷的word技巧---删除行前的空格
- Android学习笔记(36):Android的两种事件处理方式
- Linux 下wifi 驱动开发(三)—— SDIO接口WiFi驱动浅析
- Linux远程无密码登陆并远程执行脚本