php创建高清缩略图具体使用方法
发布时间:2022-08-25 13:58:28 所属栏目:PHP教程 来源:互联网
导读:1.用imagecreatetruecolor和imagecopyresampled函数分别取代imagecreate和imagecopyresized. 2.给imagejpeg的第三个参数带上100(例:imagejpeg($ni,$tofile,100)) imagecreatetruecolor -- 新建一个真彩色图像 说明:resource imagecreatetruecolor ( int x_si
1.用imagecreatetruecolor和imagecopyresampled函数分别取代imagecreate和imagecopyresized. 2.给imagejpeg的第三个参数带上100(例:imagejpeg($ni,$tofile,100)) imagecreatetruecolor -- 新建一个真彩色图像 说明:resource imagecreatetruecolor ( int x_size, int y_size ) imagecreatetruecolor() 返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像. header ("content-type: image/png"); $im = @imagecreatetruecolor (50, 100) or die ("cannot initialize new gd image stream"); $text_color = imagecolorallocate ($im, 233, 14, 91); imagestring ($im, 1, 5, 5, "a simple text string", $text_color); imagepng ($im);//开源代码phpfensi.com imagedestroy ($im); 如果使用普通的imagecreate()函数将造成图片质量失真的情况,从网上搜了一下解决办法,方法是用imagecreateruecolor()函数替换imagecreate()函数. function createpreview($img,$name,$path,$maxwidth,$maxheight,$quality){//图片,保存名称,保存路径,最大宽,最大高,质量 $widthratio=0; $heightratio=0; $width=imagesx($img); $height=imagesy($img); //开始计算缩小比例 if($width>$maxwidth||$height>$maxheight){ if($width>$maxwidth){ $widthratio=$maxwidth/$width; } if($height>$maxheight){ $heightratio=$maxheight/$height; } if($widthratio>0&&$heightratio>0){ if($widthratio<$heightratio){ $ratio=$widthratio; }else{ $ratio=$heightratio; } }elseif($widthratio>0){ $ratio=$widthratio; }elseif($heightratio>0){ $ratio=$heightratio; } //根据得出的比例,重新计算缩略图的宽和高 $newwidth=$ratio*$width; $newheight=$ratio*$height; $newimg=imagecreatetruecolor($newwidth,$newheight); // 创建目标图 imagecopyresized($newimg,$img,0,0,0,0,$newwidth,$newheight,$width,$height); imagejpeg($newimg,$path."s_".$name,$quality); imagedestroy($newimg); }else{ imagejpeg($img,$path."s_".$name,$quality); }//开源代码phpfensi.com } imagecopyresamples(),其像素插值算法得到的图像边缘比较平滑,质量较好,但该函数的速度比 imagecopyresized() 慢. (编辑:我爱制作网_潮州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |