Paint string value with different colors and position : Draw String « Graphics Image « PHP






Paint string value with different colors and position


<html>
<body>
<?php
   $img=ImageCreate(300,300);

   $bgcolor=ImageColorAllocate($img,200,200,200);
   $red=ImagecolorAllocate($img,255,0,0); 
   $green=ImagecolorAllocate($img,0,255,0); 
   $blue=ImagecolorAllocate($img,0,0,255); 
   $grey=ImagecolorAllocate($img,50,50,50); 
   $black=ImagecolorAllocate($img,0,0,0); 
                                                            
                                                            
   ImageString($img,0,20,20,"www.java2s.com",$red);
   ImageString($img,1,20,40,"www.java2s.com",$green);
   ImageString($img,2,20,60,"www.java2s.com",$blue);
   ImageString($img,3,20,80,"www.java2s.com",$grey);
   ImageString($img,4,20,100,"www.java2s.com",$black);
   ImageString($img,5,20,120,"www.java2s.com",$red);
                                                            
   ImageStringUp($img,0,50,200,"www.java2s.com",$red);
   ImageStringUp($img,1,100,200,"www.java2s.com",$green);
   ImageStringUp($img,2,150,200,"www.java2s.com",$blue);
   ImageStringUp($img,3,200,200,"www.java2s.com",$grey);
   ImageStringUp($img,4,250,200,"www.java2s.com",$black);
   ImageStringUp($img,5,300,200,"www.java2s.com",$red);
                                                            
   ImageSetPixel($img,50,50,$pixelcolor);
   ImagePNG($img,"pic.png");
   ImageDestroy($img);
?>
<img src="pic.png" border=0>
</body>
</html>
           
       








Related examples in the same category

1.Draw char with color
2.Draw string and fill rectangle
3.Using a Bounding Box to Center Text
4.Drawing a Square and a string