// 现在我们先画一条线吧。画线的函数是这样的: // imageline (int im, int x1, int y1, int x2, int y2, int col); // 第一个参数im,就是图象的ID,后面的 x1,y1,x2,y2,不用说了, // 是起点(x1,y1) 终点(x2,y2)的坐标呀!(图象的左上角坐标是 (0,0) ) // 最后一个参数是什么呀?是颜色!GD要求针对图象定义颜色,用定义的这些颜色来作图。 // 为什么要针对图象定义颜色?我猜测,是为了GIF、PNG等图象用之做“调色板”的。 // 这牵扯到图象本身的知识,这里不赘述了。 // 所以,画线之前,我们还要先定义颜色(真麻烦)。
// $col_red = ImageColorAllocate($im, 255,192,192); // This function has four parameters, the first $im... Do I still need to say it every time? I won’t say it next time! // The next three parameters are the red (R), green (G), and blue (B) components of the color to be defined, between 0 and 255. // This again involves physics-optics knowledge. The different light components of the three primary colors of red, green and blue, // produce ever-changing colors. The color I defined above is 255 red, 192 green, and 192 blue. // If I'm not mistaken, this is a brighter red. Let's try to draw a line in a moment. // Why wait a while? Because if a picture has only one color, nothing can be seen! // Let’s make the background black first! // Although it is not clearly stated in the manual, I found that the color defined first will be used as the background by default.
$col_black = ImageColorAllocate($im, 0,0,0); // Defines a color. There is no red light, green light, or blue light. Natural black - black. // Then define the color for drawing the line: $col_red = ImageColorAllocate($im, 255,192,192);
// Now you can start drawing the red line: imageline ($im , 10, 20, 45, 85, $col_red); // Don’t worry, you won’t be able to see the image after finishing this sentence.
ImagePNG($im); // This sentence outputs an image. ImagePNG() outputs a png image, ImageJPEG outputs a jpeg image, // ImageGIF outputs a gif image... … // Don’t forget there is a parameter here. If it is displayed on the screen instead of saved as a file, // then omit this parameter - the saved file name. If you want to save it as a file here, // You should write it like this: ImagePNG($im, "test.png"); // If you don’t specify a path, this file will be saved in your web page. in the directory. // If it is JPEG, there is one more parameter, which is JPEG quality (0~100). // If you want to display it on the screen, then ImageJPEG($im,"",80); // If you want to save it, then ImageJPEG($im,"test.jpg",80); // Note that if you want to save this image as a file, // you cannot use Header("Content-type: image/png"); to send the HTTP header that means the image, // Because once this happens, it means you will output the image.
ImageDestroy($im); // Destroy the image in memory to free up memory space. // That’s it: the simplest GD drawing is done.
// Through testing, it was found that the PNG format used to generate this image file only has 131 bytes. // And the JPEG format, even with the worst quality (0), requires 855 bytes, the image quality is too bad to watch. // The highest JPEG quality requires 2360 bytes, but the colors are still not as vivid as when using PNG. // It can be seen that for this kind of image with a small number of colors, using PNG is much more cost-effective than JPEG. ?>
This time I will stop here and I will try to continue writing as soon as possible.
http://www.bkjia.com/PHPjc/508283.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508283.htmlTechArticleI really don’t dare to say that I am “talking” about the GD library here, because I have only used GD once or twice. Most of the functions have not been touched yet. But Sanbanzhu Xiaodiao enthusiastically asked me for a manuscript, so I had no choice but to...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn