php学习--图像处理

生成png图片代码
+展开
-PHP
$img=imagecreate(200,200);
$white=imagecolorallocate($img,0xff,0xff,0xff);
$black=imagecolorallocate($img,0x00,0x00,0x00);
//imagepolygon($im,array(10,100,30,400,50,600),3,$black);
//imagearc($im,100,100,200,150,0,270,$black);
//imagefilledrectangle($im,0,0,200,200,$black);
imagestring($img,5,50,160,"A black box",black);
header("content-type:images/png");
imagepng($img);
imagedestroy($img);



使用truecolor
+展开
-PHP
$im=imagecreatetruecolor(150,150);
$white=imagecolorallocate($im,0xff,0xff,0xff);
imagealphablending($im,true);
imagefilledrectangle($im,0,0,150,150,$white);
$red=imagecolorresolvealpha($im,255,50,0,63);
imagefilledellipse($im,75,75,80,63,$red);
$gray=imagecolorresolvealpha($im,70,70,70,63);
imagealphablending($im,false);
imagefilledrectangle($im,60,60,120,120,$gray);
imagejpeg($im);


ttf字体
+展开
-PHP
$ttf='C:\\WINDOWS\\Fonts\\';
putenv("GDFONTPATH=$ttf");//设置字体路径
$im=imagecreate(70,350);
$white=imagecolorallocate($im,0xff,0xff,0xff);
$black=imagecolorallocate($im,0x00,0x00,0x00);
//imagettftext($im,20,0,10,40,$black,"{$ttf}STCAIYUN.TTF",'
ABCDEF');//水平
imagettftext($im,20,270,10,40,$black,"{$ttf}STCAIYUN.TTF",'
ABCDEF');//垂直
header("content-type:images/png");
imagepng($im);
imagedestroy($im);


生成缩略图
+展开
-PHP
$src=imagecreatefromjpeg("1.jpg");
$w=imagesx($src);
$h=imagesy($src);
$dw=$w/2;
$dh=$h/2;
$dest=imagecreate($dw,$dh);
imagecopyresampled($dest,$src,0,0,0,0,$dw,$dh,$w,$h);

imagepng($dest);
imagedestroy($src);
imagedestroy($dest);


imagecolorat使用示例
+展开
-HTML
<html><body bgcolor="#000000"><tt>
<?php
  $im=imagecreatefromgif("php.gif");
  $dx=imagesx($im);
  $dy=imagesy($im);
  for($y=0;$y<$dy;$y++)
  {
   for($x=0;$x<$dx;$x++)
   {
$col=imagecolorat($im,$x,$y);
$rgb=imagecolorsforindex($im,$col);
printf("<font color=#%02x%02x%02x>#</font>",
$rgb["red"],$rgb["green"],$rgb["blue"]);
}
echo "<br/>\n";
  }
imagedestroy($im);
?>
</tt></body></html>


生成按钮示例
+展开
-PHP
$ttf="c:\\window\\fonts\\";
$im=imagecreate(200,200);
$bg=imagecolorallocate($im,0xff,0xff,0xff);
$color=imagecolorallocate($im,0x00,0x00,0x00);
$blue=imagecolorallocate($im,0x00,0x00,0xff);
imagefilltoborder($im,0,200,1,$blue);
header("
content-type:images/png");
imagepng($im);
imagedestroy($im);


imagecreatetruecolor及imageline
+展开
-PHP
  $im=imagecreatetruecolor(256,60);
  for($x=0;$x<256;$x++)
  {
   imageline($im,$x,0,$x,19,$x);
imageline($im,255-$x,20,255-$x,39,$x<<8);
imageline($im,$x,40,$x,59,$x<<16);
}
imagepng($im);


加支付宝好友偷能量挖...


原创文章,转载请注明出处:php学习--图像处理

评论(0)Web开发网
阅读(132)喜欢(0)PHP/apache/Perl