Talking about PHP drawing (c)

Source: Internet
Author: User

Last talk about using GD as a variety of geometries, as well as fill color. It deliberately left such a more complex situation behind, which is the fill color of freeform and freeform polygons.

<?
 Header("Content-type: image/png");
 $im = ImageCreate (200, 100);
 $col_blk = ImageColorAllocate($im, 0,0,0);
 $col_grn = ImageColorAllocate($im, 0,255,0);
 $parray = array(40,10,60,10,70,20,60,50,40,50,30,20);
 // 定义一个数组,12个成员是6个点的横纵坐标。
 ImagePolygon($im,$parray,6,$col_grn);
 // 这就是绘制任意多边形的函数,$parray是刚才定义的数组,6表示六个点。注意六个点连成的是六边形。
 // 不必人为地为了闭合图形而在最后增加一个与第一点相同的点。
 ImagePNG($im);
 ImageDestroy($im); 
?>

You should have thought of the function of the freeform fill color:

<?
 Header("Content-type: image/png");
 $im = ImageCreate (200, 100);
 $col_blk = ImageColorAllocate($im, 0,0,0);
 $col_orn = ImageColorAllocate($im, 255,192,0);
 $col_yel = ImageColorAllocate($im, 255,255,0);
 $col_red = ImageColorAllocate($im, 255,0,0);
 $col_grn = ImageColorAllocate($im, 0,255,0);
 $col_blu = ImageColorAllocate($im, 0,0,255);
 $parray = array(40,10,60,10,70,20,60,50,40,50,30,20);
 ImageFilledPolygon($im,$parray,6,$col_grn);
 ImagePNG($im);
 ImageDestroy($im); 
?>

Well. We can write on the image below. However, do not be happy, to write Chinese characters still have to cost some trouble. This is explained gradually later again. Let's take a look at how to simply write a western character.

<?
 Header("Content-type: image/png");
 $im = ImageCreate (200, 250);
 $col_blk = ImageColorAllocate($im, 0,0,0);
 $col_orn = ImageColorAllocate($im, 255,192,0);
 $str="This is a test.";
 ImageString($im,1,10,10,$str,$col_orn);
 ImageString($im,2,10,30,$str,$col_orn);
 ImageString($im,3,10,60,$str,$col_orn);
 ImageString($im,4,10,100,$str,$col_orn);
 ImageString($im,5,10,150,$str,$col_orn);
 // 这里连续五次调用ImageString,在不同位置,
 // 分别用从小到大的字型输出了字符串 $str。
 // ImageString 函数只支持五种字型(1~5)
 ImagePNG($im);
 ImageDestroy($im); 
?>

Look again:

<?
 //Header("Content-type: image/png");
 $im = ImageCreate (200, 250);
 $col_blk = ImageColorAllocate($im, 0,0,0);
 $col_orn = ImageColorAllocate($im, 255,192,0);
 $str="This is a test."; 
 ImageStringUp($im,1,10,180,$str,$col_orn);
 ImageStringUp($im,2,20,180,$str,$col_orn);
 ImageStringUp($im,3,40,180,$str,$col_orn);
 ImageStringUp($im,4,70,180,$str,$col_orn);
 ImageStringUp($im,5,110,180,$str,$col_orn);
 // 函数名换成了 ImageStringUp,用法不变。
 // 是输出竖排的文字。
 ImagePNG($im);
 ImageDestroy($im); 
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.