Date
Oct. 26th, 2024
 
2024年 9月 24日

Post: PHP Primer 023 : 图像处理(一)

PHP Primer 023 : 图像处理(一)

Published 12:02 Feb 02, 2012.

Created by @ezra. Categorized in #Programming, and tagged as #PHP.

Source format: Markdown

Table of Content

这一篇主要介绍 PHP 中的 Grahpic Device 库的使用。

CD 已经在 PHP 中集成,我们要做的很简单:

<?php
header("content-type: image/png");

新建画布

接下来,要画图首先当然要有画布:

$img = imagecreatetruecolor(100, 100);

颜色设定

为画笔设定颜色吧:

$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($img, 0x00, 0x00, 0x00);

填充画布

imagefill($img, 0, 0, $red);

线条绘制

imageline($img, 0, 0, 100, 100, $black);

输出图像

输出到浏览器中:

imagepng($img);

释放内存

imagedestroy($img);
?>
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询