位置: 编程技术 - 正文
推荐整理分享PHP:imagecopyresampled()的用法_GD库图像处理函数,希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!
(PHP 4 >= 4.0.6, PHP 5)
imagecopyresampled — 重采样拷贝部分图像并调整大小
说明 bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )imagecopyresampled() 将一幅图像中的一块正方形区域拷贝到另一个图像中,平滑地插入像素值,因此,尤其是,减小了图像的大小而仍然保持了极大的清晰度。
In other words, imagecopyresampled() will take a rectangular area from src_image of width src_w and height src_h at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_w and height dst_h at position (dst_x,dst_y).
如果源和目标的宽度和高度不同,则会进行相应的图像收缩和拉伸。坐标指的是左上角。本函数可用来在同一幅图内部拷贝(如果 dst_image 和 src_image 相同的话)区域,但如果区域交迭的话则结果不可预知。
参数dst_image
目标图象连接资源。
src_image源图象连接资源。
dst_x目标 X 坐标点。
dst_y目标 Y 坐标点。
src_x源的 X 坐标点。
src_y源的 Y 坐标点。
dst_w目标宽度。
dst_h目标高度。
src_w源图象的宽度。
src_h源图象的高度。
返回值成功时返回 TRUE, 或者在失败时返回 FALSE。
范例
Example #1 简单的例子
这个例子会将图像调整为原有尺寸的一半。
<?php//这个文件$filename='test.jpg';$percent=0.5;//内容类型header('Content-Type:image/jpeg');//获取新的尺寸list($width,$height)=getimagesize($filename);$new_width=$width*$percent;$new_height=$height*$percent;//重新取样$image_p=imagecreatetruecolor($new_width,$new_height);$image=imagecreatefromjpeg($filename);imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);//输出imagejpeg($image_p,null,);?>以上例程的输出类似于:
Example #2 按比例对图像重新采样
这个例子会以最大宽度高度为 像素显示一个图像。
<?php//源文件$filename='test.jpg';//设置最大宽高$width=;$height=;//Contenttypeheader('Content-Type:image/jpeg');//获取新尺寸list($width_orig,$height_orig)=getimagesize($filename);$ratio_orig=$width_orig/$height_orig;if($width/$height>$ratio_orig){$width=$height*$ratio_orig;}else{$height=$width/$ratio_orig;}//重新取样$image_p=imagecreatetruecolor($width,$height);$image=imagecreatefromjpeg($filename);imagecopyresampled($image_p,$image,0,0,0,0,$width,$height,$width_orig,$height_orig);//输出imagejpeg($image_p,null,);?>以上例程的输出类似于:
注释Note:
因为调色板图像限制(+1 种颜色)有个问题。重采样或过滤图像通常需要多于 种颜色,计算新的被重采样的像素及其颜色时采用了一种近似值。对调色板图像尝试分配一个新颜色时,如果失败我们选择了计算结果最接近(理论上)的颜色。这并不总是视觉上最接近的颜色。这可能会产生怪异的结果,例如空白(或者视觉上是空白)的图像。要跳过这个问题,请使用真彩色图像作为目标图像,例如用 imagecreatetruecolor() 创建的。
参见imagecopyresized() - 拷贝部分图像并调整大小
PHP:imagecreatefromwbmp()的用法_GD库图像处理函数 imagecreatefromwbmp(PHP4=4.0.1,PHP5)imagecreatefromwbmp由文件或URL创建一个新图象。说明resourceimagecreatefromwbmp(string$filename)imagecreatefromwbmp()返回一图像标识符,代表
PHP:imagecopyresized()的用法_GD库图像处理函数 imagecopyresized(PHP4,PHP5)imagecopyresized拷贝部分图像并调整大小说明boolimagecopyresized(resource$dst_image,resource$src_image,int$dst_x,int$dst_y,int$src_x,int$src_y,int$dst_w,int$dst_h
PHP:imagecreatefromstring()的用法_GD库图像处理函数 imagecreatefromstring(PHP4=4.0.4,PHP5)imagecreatefromstring从字符串中的图像流新建一图像说明resourceimagecreatefromstring(string$image)imagecreatefromstring()返回一个图像标识符
标签: PHP:imagecopyresampled()的用法_GD库图像处理函数
本文链接地址:https://www.jiuchutong.com/biancheng/288360.html 转载请保留说明!友情链接: 武汉网站建设