本文实例讲述了PHP生成高清缩略图的方法。分享给大家供大家参考,具体如下:
缩略图很多情况下都会失真,这个时候需要有一些对应的解决方法
。1.用imagecreatetruecolor和imageCopyreSampled函数分别取代imagecreate和imagecopyresized
2.给imagejpeg的第三个参数带上100(例:imagejpeg($ni,$toFile,100))
下面是具体的函数
$org_info[1] / $NewHeight) {
$WriteNewWidth = $NewWidth;
$WriteNewHeight = $NewWidth / ($OldImageInfo[0] / $OldImageInfo[1]);
} else {
$WriteNewWidth = $NewHeight * ($OldImageInfo[0] / $OldImageInfo[1]);
$WriteNewHeight = $NewHeight;
}
//以$NewHeight为基础,如果新宽小于或等于$NewWidth,则成立
if ( $WriteNewWidth <= $NewWidth ) {
$WriteNewWidth = $WriteNewWidth; //用判断后的大小
$WriteNewHeight = $NewHeight; //用规定的大小
$WriteX = floor( ($NewWidth-$WriteNewWidth) / 2 ); //在新图片上写入的X位置计算
$WriteY = 0;
} else {
$WriteNewWidth = $NewWidth; // 用规定的大小
$WriteNewHeight = $WriteNewHeight; //用判断后的大小
$WriteX = 0;
$WriteY = floor( ($NewHeight-$WriteNewHeight) / 2 ); //在新图片上写入的X位置计算
}
//旧图形缩小后,写入到新图形上(复制),imagecopyresized参数说明:新旧,新xy旧xy,新宽高旧宽高
@imageCopyreSampled( $NewImg,$OldImg,$WriteX,$WriteY,$WriteNewWidth,$WriteNewHeight,$OldImageInfo[0],$OldImageInfo[1] );
//保存文件
// @imagegif( $NewImg,$NewImagePath );
@imagejpeg($NewImg,100);
//结束图形
@imagedestroy($NewImg);
}
CreateSmallImage("./images/jiexie.jpg","./images/jiexie.small.jpg",200,300);
CreateSmallImage("./images/jiexie.jpg","./images/jiexie.middle.jpg",400,500);
希望本文所述对大家PHP程序设计有所帮助。
原文链接:https://www.f2er.com/php/20846.html