欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

用PHP实现图片像素级别的操作:imagesetpixel 函数详解

最编程 2024-07-28 13:47:23
...

imagesetpixel()在指定的坐标处绘制像素。

语法

PHP imagesetpixel()函数具有以下语法。

bool imagesetpixel ( resource $image , int $x , int $y , int $color )

参数

PHP imagesetpixel()函数具有以下参数。

  • image - 由图像创建函数(如imagecreatetruecolor())返回的图像资源。
  • x-x坐标。
  • y-y坐标。
  • color - 使用imagecolorallocate()创建的颜色标识符。

返回值

成功时返回TRUE,失败时返回FALSE。

实例

<?php 
/*
http://www.manongjc.com/article/1758.html
作者:码农教程
*/
        $myImage = imagecreatetruecolor( 200, 100 ); 
        $myGray = imagecolorallocate( $myImage, 204, 204, 204 ); 
        $myBlack = imagecolorallocate( $myImage, 0, 0, 0 ); 
        imagesetpixel( $myImage, 120, 60, $myBlack );   
        header( "Content-type: image/png" ); 
        imagepng( $myImage ); 
        imagedestroy( $myImage ); 
?>