教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP GD库处理JPG图片大小变模糊的解决办法

PHP GD库处理JPG图片大小变模糊的解决办法

发布时间:2017-02-25   编辑:jiaochengji.com
本文介绍下,在使用php中的GD库处理 JPG 图片时,出现大小变模糊问题的解决方法,有需要的朋友参考学习下。

问题描述:
在用PHPCMS的thumb函数时,JPG图片变化大小后,质量会下降很多。
经研究,是PHP的imagejpeg函数的问题,最后修改此函数为imagepng后,问题得以解决。

下面把实现代码,分享给大家。
代码:
 

复制代码 代码示例:

<?php
header("Content-type: image/png");

$temp_width = 150;
$temp_height = 180;

$img_path = "test.jpg";
$img_path2 = "test2.jpg";

$im = @imagecreatefromjpeg($img_path);

$temp_img=imagecreatetruecolor($temp_width,$temp_height);
imagecopyresampled($temp_img,$im,0,0,0,0,$temp_width,$temp_height,$temp_width,$temp_height);
//echo $temp_img;
//imagejpeg($temp_img);
imagepng($im,$img_path2);

/*
imagecopyresized($temp_img,$im,0,0,0,0,$temp_width,$temp_height,$srcW,$srcH);
$ni=imagecreatetruecolor($width,$height);
imagecopyresampled
$res = function_exists('imagecreatetruecolor');
var_dump($res);
*/
?>
<br />
<img src="http://www.jbxue.com/ /test.jpg"/>

您可能感兴趣的文章:
PHP GD库处理JPG图片大小变模糊的解决办法
php GD库函数getimagesize()的用法
php绘图不显示图片怎么办
windows下开启PHP GD库的方法
php gd库的基础知识
PHP图片裁剪函数(图像不变形)
php开启GD库(windows环境)
Linux下开启PHP GD库支持
AI源文件转photoshop图像变模糊问题解决教程
uc浏览器浏览时图片模糊怎么回事

[关闭]
~ ~