初学PHP!
看这个题目,我觉得又把标题妖化了!
不过我觉得,也许我的想法可能会给大家的学习来点思路!
举例说明:
array getimagesize ( string $filename [, array &$imageinfo ] )
getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型和一个可以用于普通 HTML 文件中 IMG 标记中的 height/width 文本字符串。
imagecreatefromgif()
resource imagecreatefromgif ( string $filename )
imagecreatefromgif() 返回一图像标识符,代表了从给定的文件名取得的图像。
意思就是以后为了方便使用这个图片资源,这个函数返回一个操作的句柄。
类似的函数还有imagecreatefromjpeg(),imagecreatefrompng() 当然还有很多,大家可以看官方在线手册
int imagecolorat ( resource $image , int $x , int $y )
返回 image 所指定的图形中指定位置像素的颜色索引值。
<?php
$url = "logo-yy.gif";
$size = getimagesize($url);
$width = $size[0];
$height = $size[1];
$im = imagecreatefromgif($url);
for($y=1;$y<$height;$y++){
for($x=1;$x<$width;$x++){
$color_index = imagecolorat($im, $x, $y);
$color_tran = imagecolorsforindex($im, $color_index);
echo("<span class=\"c\" style=\"color:RGB(".$color_tran['red'].",".$color_tran['green'].",".$color_tran['blue'].");\">");
echo("爱");
echo("</span>");
}
echo("<br>");
}
?>
要注意的是我的程序里用的函数是imagecreatefromgif()
所以变量$url指向的文件应该是GIF格式的,如果想指向JPG格式的文件要用imagecreatefromjpeg()
当然我们可以写在一起,因为第一个函数就可以判断图片的格式,我在这里就不写了!!哈哈
好了,有php环境的赶紧试试是什么吧!呵呵